Python Forum

Full Version: Help with raw_input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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"
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.
Thank you ichabod801 for the help!:)