This repository was archived by the owner on Oct 20, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy path13_02_BonusExample.py
More file actions
74 lines (49 loc) · 2.28 KB
/
Copy path13_02_BonusExample.py
File metadata and controls
74 lines (49 loc) · 2.28 KB
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
# Re-using the bonus example code from day 12 as a baseline - with a focus on decoupling functions.
feet_inches = input("Enter feet and inches:")
def parse(feet_inches):
parts = feet_inches.split(" ")
feet = float(parts[0])
inches = float(parts[1])
# return feet, inches # we can do better than this by creating a {dictionary}.
return {"Feet": feet, "Inches": inches}
def convert(Feet, Inches):
meters = Feet * 0.3048 + Inches * 0.0254
return meters
parsed = parse(feet_inches)
# result = convert(feet_inches)
result = convert(parsed["Feet"], parsed["Inches"])
print(f"\n{parsed['Feet']} feet and {parse(feet_inches)['Inches']} inches is equal to {result} meters.\n") # Here we see 3 different ways to call the output of a function in an f-string.
if result < 1:
print("Kid is too small to rise the slide. He will be eaten by a grue if he attempts it.")
else:
print("Kid can use the slide.")
# Quiz:
year_of_birth = int(input("Please enter your year of birth as an integer, for example, 1983."))
def get_age(year_of_birth, current_year = 2023):
age = current_year - year_of_birth
return age
print(get_age(1983))# Re-using the bonus example code from day 12 as a baseline - with a focus on decoupling functions.
feet_inches = input("Enter feet and inches:")
def parse(feet_inches):
parts = feet_inches.split(" ")
feet = float(parts[0])
inches = float(parts[1])
# return feet, inches # we can do better than this by creating a {dictionary}.
return {"Feet": feet, "Inches": inches}
def convert(Feet, Inches):
meters = Feet * 0.3048 + Inches * 0.0254
return meters
parsed = parse(feet_inches)
# result = convert(feet_inches)
result = convert(parsed["Feet"], parsed["Inches"])
print(f"\n{parsed['Feet']} feet and {parse(feet_inches)['Inches']} inches is equal to {result} meters.\n") # Here we see 3 different ways to call the output of a function in an f-string.
if result < 1:
print("Kid is too small to rise the slide. He will be eaten by a grue if he attempts it.")
else:
print("Kid can use the slide.")
# Quiz:
year_of_birth = int(input("Please enter your year of birth as an integer, for example, 1983."))
def get_age(year_of_birth, current_year = 2023):
age = current_year - year_of_birth
return age
print(get_age(1983))