Question:

If the user types '0' at the prompt what gets printed?

def getinput():
    print "0: start"
    print "1: stop"
    print "2: reset"
    x = raw_input("selection: ")
    try:
        num = int(x)
        if num > 2 or num < 0:
            return None
        return num
    except:
        return None

num = getinput()
if not num:
    print "invalid"
else:
    print "valid"

Answers:


Keywords:

© 2017 QuizBucket.org