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.


    Pythonista is telling my input is not defined

    Pythonista
    pythonista
    2
    4
    3089
    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.
    • ducky908
      ducky908 last edited by

      I just started learning to code and wanted to do more when I'm not on my laptop so downloaded Pythonista. I made this script and when I compiled it I get an error stating that my input is not defined. How can you define your input?

      Here is the code:

      coding: utf-8

      name = input("what is your name? ")
      age = int(input("what is your age?"))

      if (age >= 18) and (age < 90):
      print("You can vape {}" .format(name))
      if age > 90:
      print("{} vaping is not recommended" .format(name))
      else:
      print("wait {} years" .format(18 - age))

      Phuket2 2 Replies Last reply Reply Quote 0
      • Phuket2
        Phuket2 @ducky908 last edited by Phuket2

        @ducky908 , your code is ok as far as I can tell, it's just the indentation.

        The below works, only difference is the code is indented correctly

        name = input("what is your name? ")
        age = int(input("what is your age?"))
        
        if (age >= 18) and (age < 90):
        	print("You can vape {}" .format(name))
        if age > 90:
        	print("{} vaping is not recommended" .format(name))
        else:
        	print("wait {} years" .format(18 - age))
        
        1 Reply Last reply Reply Quote 0
        • Phuket2
          Phuket2 @ducky908 last edited by ccc

          @ducky908 , sorry. I was running python 3.5x, I guess you are running python 2.7.x

          But for 2.7x the below works. It's using raw_input

          coding: utf-8
          
          try:
              raw_input
              input = raw_input  # Python 2
          except NameError:      # Python 3
              pass
          
          name = input("What is your name? ").strip()
          age = int(input("What is your age? "))
          
          if 18 <= age < 90:
          	print("You can vape {}." .format(name))
          if age >= 90:
          	print("{} vaping is not recommended." .format(name))
          else:
          	print("Wait {} years." .format(18 - age))
          
          ducky908 1 Reply Last reply Reply Quote 0
          • ducky908
            ducky908 @Phuket2 last edited by

            @Phuket2 I downloaded Pythonista 3 and everything works now.

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