Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Something is wrong with while loops and strings
-
I'm a bit of a noob with programming however on python IDE this code works fine
<pre>while True:
Name = str ( input('enter name')
print (Name)</pre>Is that a small bug your working on or am I doing something wrong?
Please can anyone help
Thanks in advance -
1.- Indent correctly
2.- Close second parenthesis
3.- Use raw_input() instead of input() -
Thank you for your help jose3f.
-
I think the print statement is also set up wrong.
You are probably using Python 3.2 in your computer, whereas this is Python 2.6.. The print statement changed.
In Python 2.6, you don't use brackets in print. Instead you just say for example
print Name
print "Nachos are good"
print "Don't you agree, "+str(Name)+"?" -
@eliskan: Pythonista is Python 2.7.
And the form print() is correct. You can use both forms of print.
Try in Pyhthonista autocomplete pr and you can see both print and print() is offered to autocomplete.
-
@Eliskan
To paraphrase a tutorial I once read, the parens of the print statement are not needed, but help prevent the print statement from getting confused.Cubbarooney
-
In general, it's preferable <em>not</em> to use parentheses in 2.7. While it's not a syntax error, the semantics are different from 3.x, specifically when you print multiple, comma-separated values (for single values, the result is the same).
For example, using <code>print('foo', 'bar')</code> will print <code>('foo', 'bar')</code> in 2.7, but <code>foo bar</code> in 3.x (what you'd get without the parentheses in 2.7). So 2.7 doesn't actually treat the parentheses as part of a function call, but rather creates a tuple with both values and prints that. It would be equivalent to:
<pre>t = ('foo', 'bar') # create a tuple
print t</pre>
So it'll still work, but the result might not be what you want in most cases. -
Ahh thanks for clearing that up!