wrong is not defined Python 2.5

This is the place for queries that don't fit in any of the other categories.

wrong is not defined Python 2.5

Postby toastedPC » Sun Nov 17, 2013 12:16 am

Hi, I am relatively new to the whole python scene and was trying to write a code for a conversation and got as far as:
Code: Select all
name = raw_input ("Hello, I am Jacob what is your name? ")
problem = input ("Nice to meet you " + name + "! Can you do math? I can! give me a simple problem! ")
print problem
been = raw_input("Pretty cool huh? So, how's your day going? ")
if been.find('good') > 0:weather = raw_input ("Glad to hear it! My day is going pretty good too! What's the weather like where you're at?")
if been.find('bad') > 0:wrong = raw_input ("I'm sorry to hear that, what's wrong? ")
if wrong.find("sick") > 0:print "I hope you feel better soon!"

My problem is that whenever I press F5 that I can get all the way until I type in how my day is going and then I get an error that says:
Code: Select all
Traceback (most recent call last):
  File "C:\Python25\Doc\Conversation.py", line 7, in <module>
    if wrong.find("sick") > 0:print "I hope you feel better soon!"
NameError: name 'wrong' is not defined

and I'm not sure what's wrong. It could be something really simple that I'm just missing but if you could look over it and tell me what I'm doing wrong then please respond with an edit
Last edited by Mekire on Sun Nov 17, 2013 4:53 am, edited 1 time in total.
Reason: lock.
toastedPC
 
Posts: 6
Joined: Sat Nov 16, 2013 4:26 pm

Re: wrong is not defined Python 2.5

Postby stranac » Sun Nov 17, 2013 12:34 am

Please don't put conditionals and their blocks on the same line, that makes the code really hard to read.

You're only defining wrong when been.find('bad') > 0
If that condition is not true, you're using a variable that's not defined, which results in an exception.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 5 guests