[RESOLVED] [Python] Get User Input-VBForums
Results 1 to 2 of 2

Thread: [RESOLVED] [Python] Get User Input

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    4,467

    Resolved [RESOLVED] [Python] Get User Input

    I'm trying to teach myself Python and it looks pretty easy to be honest. But one thing that I'm not able to do is get user input. I've tried raw_input() but whenever I run my program it says that it isn't defined. This is what I'm trying to run:

    python Code:
    1. print ("Hello world, please enter in a Celsius temperature:")
    2. celsius = raw_input()
    3.  
    4. fahrenheit = celsius * 9/5 + 32
    5.  
    6. print(celsius + " degrees Celsius is " + fahrenheit + " Fahrenheit")

    The error I get is:
    NameError: name 'raw_input' is not defined
    My question to y'all is: am I doing it wrong and is there a different way?

  2. #2

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    4,467

    Re: [RESOLVED] [Python] Get User Input

    I figured out what I was doing wrong. I'm using Python 3.3.2 and raw_input was depreciated. I replaced raw_input with input, converted the input to an integer because it returns a string, as well as converting the integer back to a string when I print the result:

    python Code:
    1. print ("Hello world, please enter in a Celsius temperature:")
    2. celsius = int(input())
    3.  
    4. fahrenheit = celsius * 9 / 5 + 32
    5.  
    6. print(str(celsius) + " degrees Celsius is " + str(fahrenheit) + " Fahrenheit")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.