I need help with an online tutorial (this is not homework)
http://www.upriss.org.uk/python/session3.html
It is something very simple, but I am a beginner so I don't understand yet.
Write a script that asks someone to input their first name, last name and phone number. If the user does not type at least some characters for each of these, print "Do not leave any fields empty" otherwise print "Thank you". (Hint: if a variable is empty, its value will be "false".)
So, this is the solution page:
http://www.upriss.org.uk/python/answers3.txt
And the correct implementation is this:
fname = raw_input ("Please, type in your first name: ")
lname = raw_input ("Please, type in your last name: ")
phone = raw_input ("Please, type in your phone number: ")
if fname and lname and phone:
print "Thank you!"
else:
print "Do not leave any fields empty"
Why is that the code that I wrote does not work:
a = raw_input("Enter your first name:")
b = raw_input("Enter your last name:")
c = raw_input("Enter your phone number:")
print a
print b
print c
d = (a and b and c)
print d
if d == 0:
print "Do not leave any fields empty"
d would never get printed, and the "Do not leave any fields empty" never gets printed either.
So, when I omit to type something into one of these variables, what is its actual value.
Is it the number zero, is it the string "0", is it a special value called "false", or is it something else?