Computer Science Canada Conversion With 2 Languages Help |
Author: | Anonymous [ Tue May 30, 2006 7:26 pm ] | ||||
Post subject: | Conversion With 2 Languages Help | ||||
Ok I have some Turing code which I wish to convert to Python. These two codes look exactly the same, but Python wont spit out my choice and gives me an error. Please help: TURING:
PYTHON:
|
Author: | wtd [ Tue May 30, 2006 9:33 pm ] | ||
Post subject: | |||
You may wish to make your code take adavantage of Python a bit more.
|
Author: | Anonymous [ Wed May 31, 2006 11:03 pm ] | ||
Post subject: | RE: Python | ||
Coolz. I like Python. So the percentages corrispond with whatever is in the brackets? Since I'm used to Turing, I'd think that whatever is displayed in the quotes either displays, indents, or moves down a line. You always have %s, is that what you have to use? Or is it just recommended? Also, how would I make it so the program recognizes an item as been entered, and then add another item. So I have this:
I want it to check if a slot is open with (empty) in it, and replace it with the entered item, eg: "You equip the sword, a(1) = sword." "You equip the shield, a(2) = shield". Instead of (empty), display what is equipped =) And one last question, your "While True", does that just loop it forever, until it somehow returns false? I try to use the Python Docs, but I get a "Page is Not Displayed" error, or whatever. I do have IE7 Beta, but when I had IE6 it did the same.[/code] |
Author: | wtd [ Thu Jun 01, 2006 12:53 am ] | ||||||
Post subject: | |||||||
Well, something like "Hello %s" is a format string. The "%s" is a format specifier. It says that the value inserted here should be a string. There are other specifiers for different types of values. Now, we can use % in this case to substitute values into the format string to build a new string. Let's say:
And we get:
The parentheses I'm using when I have more than one value to deal with. The problem is, the general form is: format-string % value In order to use multiple values, we have to group them into a single value. In many cases, the easiest way to do that is to construct a tuple.
As for "while True", well, "while" loops until the expression that follow evaluate to False. Since True is always True, then yes, it loops forever. Unless of course something inside the loop causes it to exit. |