age check python

Solutions on MaxInterview for age check python by the best coders in the world

showing results for - "age check python"
Kelsey
21 Apr 2019
1#  Imports
2import datetime
3import time
4while True:
5    #  Variables & Big Catching
6    age = input('What year where you born? ')
7    current_time = datetime.datetime.now().year
8    if age.isdigit() is False:
9        print('Please enter a number')
10        quit()
11    elif len(age) != 4:
12        print('Please enter a valid year!')
13        quit()
14    elif age.isdigit() and len(age) == 4:
15        int_age = int(age)
16    if int_age < 1900:
17        print('Please enter a valid year!')
18        quit()
19    elif int_age > current_time:
20        print('Please enter a valid year!')
21        quit()
22    final_age = current_time - int_age
23    print('You are', final_age, 'or', final_age - 1, 'years old')
24
25    time.sleep(1)
26
27   
Izia
15 Sep 2020
1#  Imports
2import datetime
3
4#  Variables & Big Catching
5age = input('What year where you born? ')
6if age.isdigit() is False:
7    print('Please enter a number')
8    quit()
9elif len(age) != 4:
10    print('Please enter a valid year!')
11    quit()
12elif age.isdigit() is True and len(age) == 4:
13    int_age = int(age)
14current_time = datetime.datetime.now().year
15print('You are', current_time - int_age, 'Years old')
16
Jessica
22 May 2016
1import datetime
2try:
3    current_year = datetime.datetime.now().year
4    print(current_year)
5    print('Must be over 18!')
6    age = int(input('How old are you? '))
7    if age > 18 or age == 18:
8        print('You are over 18!')
9        born_year = int(input('What year were you born in? '))
10        born_year_output = current_year - born_year
11        born_year_minus = born_year_output - 1
12        if born_year_output == age:
13            print('You are really over 18!')
14            name = input('What is your first name? ')
15            last_name = input('What is your last name? ')
16            print(f'You are {age} years old and your name is {name} {last_name}')
17        elif born_year_minus == age:
18            print('You are really over 18!')
19            name = input('What is your first name? ')
20            last_name = input('What is your last name? ')
21            print(f'You are {age} years old and your name is {name} {last_name}')
22        else:
23            print('You are not over 18!')
24            quit()
25    else:
26        print('you are not over 18!')
27        quit()
28
29    text_file = open("userdata.txt", "w")
30    n = text_file.write(f'Name: {name} {last_name}, age: {age}. born in {born_year} \\')
31    text_file.close()
32except Exception as e:
33    print(f'Error: {e}')
34    quit()
35
36