omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    5
    8
    5705
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ylb609897
      ylb609897 last edited by

      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 Reply Last reply Reply Quote 0
      • jose3f23
        jose3f23 last edited by

        1.- Indent correctly
        2.- Close second parenthesis
        3.- Use raw_input() instead of input()

        1 Reply Last reply Reply Quote 0
        • ylb609897
          ylb609897 last edited by

          Thank you for your help jose3f.

          1 Reply Last reply Reply Quote 0
          • eliskan175
            eliskan175 last edited by

            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)+"?"

            1 Reply Last reply Reply Quote 0
            • jose3f23
              jose3f23 last edited by

              @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.

              1 Reply Last reply Reply Quote 0
              • Cubbarooney104
                Cubbarooney104 last edited by

                @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

                1 Reply Last reply Reply Quote 0
                • omz
                  omz last edited by

                  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.

                  1 Reply Last reply Reply Quote 0
                  • eliskan175
                    eliskan175 last edited by

                    Ahh thanks for clearing that up!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors