Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with raw_input
#1
I have this as a sample code but my questions of 'How are you?' and 'Do you like computers?' do not return the correct answers to my input. Any help would be great Smile



q_name = raw_input('What is your name?  ')
    print 'Hello %s.' %q_name

how_are = raw_input('How are you?  ').lower
if how_are == 'good' or how_are =='great' or how_are =='fantastic':
    print 'Im glad to hear.'
elif how_are == 'bad' or how_are == 'not good' or how_are == 'awful':
    print 'Im sorry to hear'
else:
    print "I am sorry, I am a computer and don't have emotions."


q_comp = raw_input('Do you like computers?  ').lower
if q_comp == 'yes':
    print 'Awesome!'
else:
    print "That's dumb"
Reply
#2
Please use python tags (https://python-forum.io/misc.php?action=help&hid=25). I added them for you this time.

The problem is that you need parens after lower, like so:

how_are = raw_input('How are you? ').lower()
That's how you call a function or method to get the value it produces. The way you have it, how_are ends up being the lower method itself. Note this oddity:

>>> x = 'SPAM'.lower
>>> x()
'spam'
After the first line, x is the method itself, and displays as nothing. We can then call x, by using parentheses, to get the result we were looking for. But do it the first way I showed you. The second way is just silly.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thank you ichabod801 for the help!:)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Going thru tutorials..."NameError: name 'raw_input' is not defined" hmonnier 4 4,249 Jul-14-2020, 02:19 PM
Last Post: BitPythoner
  raw_input vs input EmilySenechal 1 2,370 Nov-20-2018, 02:13 AM
Last Post: ichabod801
  raw_input rtbr17 3 3,696 Sep-26-2018, 09:36 PM
Last Post: nilamo
  URL via raw_input, passed to HTTP requests and output? johnnyaustin 1 4,907 Dec-08-2017, 11:22 PM
Last Post: johnnyaustin
  Cmd Module + raw_input tab [complete ruggierom 1 3,495 Feb-06-2017, 12:43 AM
Last Post: ruggierom
  Any way to get raw_input to work in my function? Pythonerous 4 5,265 Oct-27-2016, 05:03 PM
Last Post: Pythonerous

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020