-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3calc.py
More file actions
36 lines (29 loc) · 879 Bytes
/
3calc.py
File metadata and controls
36 lines (29 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# A python function to determine the name and birthday of the user
year = 2026
name = input("What is your name?")
#RULE --> Wrap the line that can fail, not the line before
#get users age while preventing false inputs
try:
age = int(input("How old are you? "))
if age <= 0:
raise ValueError
except ValueError:
print("Invalid age. Please enter a positive number.")
exit()
#NO LONGER NECESSARY DUE TO try FUNCTION
#convert age from string to integer
#age = int(age)
#calculate birth year
birth = (year - age)
#print users name and birth year
print(f"Hello {name} you were born in {birth}")
#determine age range of the user
if age < 13:
print("You are a child")
elif 13 <= age <= 19:
print("You are a teen")
else:
print("You are an adult")
#print users age 10 years from now
future = (age + 10)
print(f"In 10 years you will be {future} years old")