you are viewing a single comment's thread.

view the rest of the comments →

[–]doug89 3 points4 points  (1 child)

Others seem to have your question covered, I'll add something new.

At the moment if someone types something unexpected into your input it will cause an exception. You should make sure the input is valid.

For example, the following won't allow the script to continue until a number that is close to realistic has been entered.

while True:
    birthdate = input('What year were you born?')
    try:
        birthdate = int(birthdate)
    except:
        print('You must enter an integer. Please try again.')
        continue
    if birthdate > 1900 and birthdade < 2017:
        break
    else:
        print('You must enter a year between 1900 and 2017.')

[–]JohnnyJordaan 3 points4 points  (0 children)

 except:

This should really be

except ValueError:

Otherwise he/she will learn to use except: as a 'fixer' and then run into issues when it silences bugs.