-2

My code:

    reask = input('So do you want me to solve a quadratic equation? Last chance or I will close and you have to start me again! Make sure you type \'yes\' or \'no\': ')
reask = reask.lower
if reask == 'yes':
    print ('Great!')
else:
    print ('See ya!')
    raise SystemExit

When the user inputs 'yes', the program interprets it as something else and ends up printing out 'See ya!' then closing the program. It's supposed to print 'Great!'. What's the issue?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
  • 1
    You have a typo. `reask = reask.lower` should be `reask = reask.lower()`. You were setting `reask` to the function `lower`, rather than calling the function. – Loocid Sep 19 '18 at 03:04
  • 1
    `reask.lower` returns the function object and not the result which you intended – Yaman Jain Sep 19 '18 at 03:05
  • Oh my god I didn't even care to look for that. Thanks! – user10059620 Sep 19 '18 at 03:05
  • How come parentheses are needed? Why isn't there anything in the parentheses? – user10059620 Sep 19 '18 at 03:06
  • Parentheses are needed to distinguish between the function itself, which is an object like any other, versus a _call_ to the function. There is nothing in the parentheses because this particular function takes no arguments. – John Gordon Sep 19 '18 at 03:11

1 Answers1

0

The line reask = reask.lower does not do what you think it does. It binds the name reask to the method str.lower bound to the user input string.

To call this method and assign the result instead of the method itself, do reask = reask.lower().

Alternatively, you can keep the assignment as-is and change the conditional to if reask() == 'yes':. That would call the method just the same.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264