-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputsConditionalsAndCalculators.py
More file actions
223 lines (192 loc) · 6.92 KB
/
InputsConditionalsAndCalculators.py
File metadata and controls
223 lines (192 loc) · 6.92 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
################################
# Author: Rahim Siddiq
# Inputs, Conditionals, and Calculators
################################
### Problem 1 ###
# Message to user defining program function #
print("Please enter your age to see if you are eligible to obtain a driver's license")
# User input for age #
age = int(input("Please enter your age: "))
# Define min/max age, output specific messages for valid conditionals and output to user #
if age in range(0, 130):
if age in range(18, 96):
print("You are eligible to apply for a driver's license")
elif age < 18:
print("Sorry, you are too young to apply for a driver's license at this time")
elif age >= 96:
print("Sorry, the maximum age to apply for a driver's license is 95")
else:
print("Please enter a valid number for your age")
### Problem 2 ###
# Message to user defining program function #
print("Please enter a number to see if it is greater, less, or equal to a second number")
# Prompt user input and assign variables #
n1 = float(input("Please enter the first number: "))
n2 = float(input("Please enter the second number: "))
# Conditionals and outputs to user #
if n1 > n2:
print(n1, "is greater than", n2)
elif n1 < n2:
print(n1, "is less than", n2)
else:
print(n1, "is equal to", n2)
### Problem 3 ###
# Message to user defining program function #
print("Enter 5 scores to average and see your grade:")
# Prompt user input and assign variables #
s1 = float(input("Please enter your first score: "))
s2 = float(input("Please enter your second score: "))
s3 = float(input("Please enter your third score: "))
s4 = float(input("Please enter your fourth score: "))
s5 = float(input("Please enter your fifth score: "))
# Definition of functions #
sums = (s1 + s2 + s3 + s4 + s5)
avg = sums / 5
print("Your average score =", avg)
# Conditionals and user output #
if avg >= 90:
print("Your grade = A")
elif avg >= 80:
print("Your grade = B")
elif avg >= 70:
print("Your grade = C")
elif avg >= 60:
print("Your grade = D")
else:
print("Your grade = F")
### Problem 4 ###
# Message to user defining program function and parameters they can select #
print("To see the breakdown of a month in days, hours, minutes and seconds. "
"Please enter the number of the month.")
print("1: January")
print("2: February")
print("3: March")
print("4: April")
print("5: May")
print("6: June")
print("7: July")
print("8: August")
print("9: September")
print("10: October")
print("11: November")
print("12: December")
# Prompt user for integer selection to represent month #
month = int(input("Please enter the number of the corresponding month: "))
# Conditionals and output to user #
if month == 1:
days = 31
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("January can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 2:
leap = input("Is this a leap year? Enter y/n: ")
if leap == "y":
days = 29
elif leap == "n":
days = 28
else:
print("Enter y/n for: Is this a leap year?")
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("February can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 3:
days = 31
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("March can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 4:
days = 30
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("April can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 5:
days = 31
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("May can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 6:
days = 30
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("June can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 7:
days = 31
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("July can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 8:
days = 31
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("August can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 9:
days = 30
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("September can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 10:
days = 31
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("October can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 11:
days = 30
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("November can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
elif month == 12:
days = 31
hours = days * 24
minutes = hours * 60
seconds = minutes * 60
print("December can be expressed in the following units of time:",
days, "days,", hours, "hours,", minutes, "minutes,", seconds, "seconds")
else:
print("Please enter a valid number")
### Problem 5 ###
# Message to user for program function #
print("Please enter your age in whole years, remainder days, and remainder hours "
"to see the total seconds you've lived")
# Prompt for user input, assign variables #
years = int(input("Enter the number of years since your birth: "))
days = int(input("Enter the remainder of days: "))
hours = int(input("Enter the remainder of hours: "))
leap = input("Would you like to factor in leap years? y/n: ")
# Conditionals and user output #
if leap == "y":
# Approximate leap years as years // 4
leap_days = int(years // 4)
secondsleap = ((years * 31536000) +
(leap_days * 86400) +
(days * 86400) +
(hours * 3600))
print("Seconds you have lived thus far:", secondsleap)
elif leap == "n":
seconds = ((years * 31536000) +
(days * 86400) +
(hours * 3600))
print("Seconds you have lived thus far:", seconds)
else:
print("Enter y/n for: Would you like to factor in leap years?")