-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
203 lines (183 loc) · 7.1 KB
/
Copy pathmain.py
File metadata and controls
203 lines (183 loc) · 7.1 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"""
Running Calculator Concept - for the Sada's
Copyright (C) 2022-2026 willtheorangeguy
"""
# pylint: disable=locally-disabled, invalid-name, too-many-locals, too-many-branches, too-many-statements
# Running Calculator
import sys
def calculate_distance(distance, unit):
"""Calculate the distance in meters."""
if distance > 1000:
distance = distance / 1000
unit = "kilometers"
else:
unit = "meters"
return distance, unit
def display_result(distance, unit, metersps, kmph):
"""Display the result."""
print("")
if unit == "meters":
print("You traveled " + str(round(distance, 2)) + " meters.")
else:
print("You traveled " + str(round(distance, 2)) + " kilometers.")
print(
"Your speed was "
+ str(round(metersps, 2))
+ " meters per second or "
+ str(round(kmph, 2))
+ " kilometers per hour. \n\n"
)
def main():
"""Main entry point of the app."""
# MATH CONSTANTS
FT = 3.281
MILES = 1609.344
HALF_MARATHON = 21097.5
MARATHON = 42195
# CONVERSION VARIABLES
unit = ""
# WELCOME
run = True
length_run = True
time_run = True
print(
r"""
,////,
/// 6|
// _|
_/_,-'
_.-/'/ \ ,/;,
,-' /' \_ \ / _/
`\ / _/\ ` /
| /, `\_/
| \'
/\_ /` /\
/' /_``--.__/\ `,. / \
|_/` `-._ `\/ `\ `.
`-.__/' `\ |
`\ \
`\ \
\_\__
\___)"""
)
print(
r"""
_
(_)
_ __ _ _ _ __ _ __ _ _ __ __ _
| '__| | | | '_ \| '_ \| | '_ \ / _` |
| | | |_| | | | | | | | | | | | (_| |
|_| \__,_|_| |_|_| |_|_|_| |_|\__, |
__/ |
|___/
"""
)
print(" WELCOME TO THE RUNNING SPEED CALCULATOR")
print(" Please answer each question to receive your time and speed!")
print("Note: Currently, the program only displays results in metric values. \n")
# LENGTH ENTRY
while run:
# Type of Measurement
while length_run:
length_type = str(input("What unit will you be inputting? "))
if length_type.lower() == "marathons" or length_type.lower() == "marathon":
unit = "marathon"
print("You are now entering in marathons! \n")
length_run = False
elif (
length_type.lower() == "half marathons"
or length_type.lower() == "half marathon"
):
unit = "halfmarathon"
print("You are now entering in half-marathons! \n")
length_run = False
elif length_type.lower() == "miles" or length_type.lower() == "mile":
unit = "miles"
print("You are now entering in miles! \n")
length_run = False
elif length_type.lower() == "feet" or length_type.lower() == "foot":
unit = "feet"
print("You are now entering in feet! \n")
length_run = False
elif (
length_type.lower() == "kilometers"
or length_type.lower() == "kilometer"
):
unit = "kilometers"
print("You are now entering in kilometers! \n")
length_run = False
elif length_type.lower() == "meters" or length_type.lower() == "meter":
unit = "meters"
print("You are now entering in meters! \n")
length_run = False
elif length_type.lower() == "license":
print("Running Calculator Copyright (C) 2022-2023 @willtheorangeguy")
print(
"This program comes with ABSOLUTELY NO WARRANTY;"
" for details view the license."
)
print("This is free software, and you are welcome to redistribute it")
print("under certain conditions; view the license for details. \n")
length_run = True
elif length_type.lower() == "quit" or length_type.lower() == "exit":
length_run = False
run = False
sys.exit()
else:
print("Please try again. Options are:")
print("Marathons\t 42195m")
print("Half Marathons\t 21907.5m")
print("Miles\t\t 1069.3m")
print("Feet\t\t 0.38m")
print("Kilometers\t 1000m")
print("Meters\t\t 1m")
print("license\t\t View the license file.")
print("exit\t\t Exit the program. \n")
print("quit\t\t Exit the program. \n")
length_run = True
# Value
distance = 0
while time_run:
try: # enable only numerical values
time_run = False
length = float(input("How far did you run? "))
hours = int(input("How many hours did it take you? (if < 1, enter 0) "))
mins = int(
input("How many minutes did it take you? (if < 1, enter 0) ")
)
secs = float(input("How many seconds did it take you? "))
except ValueError:
print(
"Values must be in numerical form, "
"and only seconds can be a decimal! \n"
)
time_run = True
# DISTANCE CALCULATION - conversion to meters
if unit == "marathon":
distance = length * MARATHON
elif unit == "halfmarathon":
distance = length * HALF_MARATHON
elif unit == "miles":
distance = length * MILES
elif unit == "feet":
distance = length / FT
elif unit == "kilometers":
distance = length * 1000
elif unit == "meters":
distance = length
else:
pass
# TIME CALCULATION
time = 0
time = (hours * 3600) + (mins * 60) + secs
# SPEED CALCULATION
metersps = distance / time
kmph = metersps * 3.6
# PRINT FINAL RESPONSES
distance, unit = calculate_distance(distance, unit)
display_result(distance, unit, metersps, kmph)
length_run = True
time_run = True
# Execute only if run as the entry point into the program
if __name__ == "__main__":
main()