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
    11,753

    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?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2

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

    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")
    Last edited by dday9; Oct 11th, 2013 at 11:30 AM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

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



Click Here to Expand Forum to Full Width