Jump to content
  • Advertisement
Sign in to follow this  
Zelnen

Need some very basic python help

This topic is 4015 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey i've just started python a few minutes ago and am following a tutorial but i can't get this very simple script to work. -------------------------------------------------- name = 'Jack' guess = input('Can you guess my name?') if guess == name: print 'Haha you got it right!' else guess != name : print 'You suck' ------------------------------------------------- I'm running it in PythonWin. And when i run the script the interactive window doesn't show anything at all. When i take out the else statement and run it the input box pops up etc But anyway, why doesn't it work? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You have a syntax error at:

else guess != name:

Write this instead as:

if guess == name:
print 'haha you got it right'

else:
print 'wrong answer'

Refer to http://docs.python.org/tut/node6.html for the python documentation on control flow. Basically, "else" does not take a conditional and acts as a default case in an if-elif block.

Share this post


Link to post
Share on other sites
Omg i feel so dumb! Lol it's a while since i've done programming, mm thanks ;)

EDIT


name = 'Jack'
guess = input('Can you guess my name?')

if guess == name:
print 'Haha you got it right!'

else:
print 'You suck'


Now i just get the error:

NameError: name 'jack' is not defined

Whatever input i put in it says it's not defined

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!