-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_Character_Input.py
30 lines (26 loc) · 1.04 KB
/
01_Character_Input.py
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
# import datetime module
import datetime
# Ask for user's name and age
name = input('Enter your name: ')
# Check if name contains only letters
if not name.isalpha():
raise Exception('The name can only contain letters')
# Get the user's age and convert the value to integer type
# using int() function
age = int(input('Enter your age: '))
# Get the number of repetition number.
repetitions = int(input('How many times to repeat a message: '))
# Get actual year using datetime module
actual_year = datetime.date.today().year
# Calculate the year on user's 100th birthday
year_on_100th_birthday = actual_year + (100 - age)
# Depending on age, display the right message
if age > 100:
message = f'Your 100th birthday was in {year_on_100th_birthday}'
elif age < 100:
message = f'Your 100th birthday will be in {year_on_100th_birthday}'
else:
message = f'Your 100th birthday is in {year_on_100th_birthday}'
# Depending on repetitions number, display the right number of message
for x in range(repetitions):
print(f'{name.capitalize()}, {message} \n')