Python Forum
Help with raw_input - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help with raw_input (/thread-2480.html)



Help with raw_input - Marshall_99 - Mar-21-2017

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"



RE: Help with raw_input - ichabod801 - Mar-21-2017

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.


RE: Help with raw_input - Marshall_99 - Mar-21-2017

Thank you ichabod801 for the help!:)