-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter_input.py
112 lines (83 loc) · 4 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Libraries
import datetime
# Variables
milestone = 100 # Number as milestone for age
today = datetime.date.today() # Get current date from today
year = today.year # Get the current year from today
# Functions
def create_space():
print()
def create_division():
division_string = "_______________________________________________________________________________________________________________________________________"
create_space()
print(f"{division_string}\n")
create_space()
def calculate_age_milestone(milestoneAge, currentAge):
# Simple argument datatype check
if not isinstance(milestoneAge, int) or not isinstance(currentAge, int):
print("One of the provided arguments were not the correct datatype!")
print("Milestone: ", type(milestoneAge))
print("Age: ", type(currentAge))
return False
# Calculate the year when you reach milestone
year_milestone = (year + milestoneAge) - currentAge
# Calculate how many years left until you reach milestone
years_until_milestone = year_milestone - year
# Return year until milestone and years left to reach the milestone
return year_milestone, years_until_milestone
def get_age_milestone_string(name, age, milestoneAge):
# Get the milestone
age_milestone = calculate_age_milestone(milestoneAge, age)
age_hundred = age_milestone[0]
age_until_hundred = age_milestone[1]
# Make sure the person is not already as old as the milestone
if age == milestoneAge:
return f"You fufilled {milestoneAge} years old this year, {name}. Congratulations for reaching this incredible milestone!"
elif age > milestoneAge:
return f"You are already {milestoneAge} years old and above, {name}. Congratulations for reaching this amazing milestone!"
# Tell the result to the user and consider how many years left. Then return it
if age_until_hundred == 1:
return f"You, {str.capitalize(name)} will turn 100 in the year {age_hundred}. This means that in about {age_until_hundred} year, then you will achieve that incredible milestone!"
else:
return f"You, {str.capitalize(name)} will turn 100 in the year {age_hundred}. This means that in about {age_until_hundred} years, you will achieve that massive milestone soon!"
def print_string_extra(string, separate):
try:
num_copies = int(input("Enter the number of copies: "))
except ValueError:
print("The provided amount of tries is not a real number, please try again!")
create_division()
return print_string_extra(string)
# Create an extra space
create_space()
# Print the text, separate or not. Based on the extra one and extra two tasks
if not separate:
print(string * num_copies)
create_division()
else:
print("\n".join([string] * num_copies))
create_division()
def main():
create_division()
# Get the person's name
name = str(input("Enter your name: "))
# Check if age is valid data type or not
try:
age = int(input("Enter your age: "))
except ValueError:
print("The provided age is not a valid age or number, please try again!")
create_division()
return main()
# Create a space after answer
create_space()
# Get the answer
milestone_string = get_age_milestone_string(name, age, milestone)
# Do task one of the questions
print(milestone_string)
# Get ready for the next attempt
create_division()
# Do extra task one of the questions
print_string_extra(milestone_string, False)
# Do extra task two of the questions
print_string_extra(milestone_string, True)
# Initialization
main()