def ask():
global name, loca
print "What's your name?"
name = raw_input('> ')
print "Where are you from?"
loca = raw_input('> ')
if name or loca == None:
print "Please enter valid details."
ask()
ask()
print "Alright, so you're " + name + ", from " + loca + "."
With this script, it will only ever print the last line if both of my variables are empty. If I fill in one, or both, it triggers that if, making me redo the function.
What am I doing wrong here?
You have very well isolated the problem:
Here you think it says:
But instead it says:
Where it should say:
Which is:
See, by the way, that None comparisons are better carried out with
is, since there is only oneNoneobject.Also, a more pythonic way of doing it is:
Or, seeing as “all” it’s just 2 variables:
If you don’t understand, read around a bit (the Python tutorial is excellent — go for the conditionals part). Good luck!