1+ ################################
2+ # Author: Rahim Siddiq
3+ # Inputs, Conditionals, and Calculators
4+ ################################
5+
6+ ### Problem 1 ###
7+ # Message to user defining program function #
8+ print ("Please enter your age to see if you are eligible to obtain a driver's license" )
9+
10+ # User input for age #
11+ age = int (input ("Please enter your age: " ))
12+
13+ # Define min/max age, output specific messages for valid conditionals and output to user #
14+ if age in range (0 , 130 ):
15+ if age in range (18 , 96 ):
16+ print ("You are eligible to apply for a driver's license" )
17+ elif age < 18 :
18+ print ("Sorry, you are too young to apply for a driver's license at this time" )
19+ elif age >= 96 :
20+ print ("Sorry, the maximum age to apply for a driver's license is 95" )
21+ else :
22+ print ("Please enter a valid number for your age" )
23+
24+ ### Problem 2 ###
25+ # Message to user defining program function #
26+ print ("Please enter a number to see if it is greater, less, or equal to a second number" )
27+
28+ # Prompt user input and assign variables #
29+ n1 = float (input ("Please enter the first number: " ))
30+ n2 = float (input ("Please enter the second number: " ))
31+
32+ # Conditionals and outputs to user #
33+ if n1 > n2 :
34+ print (n1 , "is greater than" , n2 )
35+ elif n1 < n2 :
36+ print (n1 , "is less than" , n2 )
37+ else :
38+ print (n1 , "is equal to" , n2 )
39+
40+ ### Problem 3 ###
41+ # Message to user defining program function #
42+ print ("Enter 5 scores to average and see your grade:" )
43+
44+ # Prompt user input and assign variables #
45+ s1 = float (input ("Please enter your first score: " ))
46+ s2 = float (input ("Please enter your second score: " ))
47+ s3 = float (input ("Please enter your third score: " ))
48+ s4 = float (input ("Please enter your fourth score: " ))
49+ s5 = float (input ("Please enter your fifth score: " ))
50+
51+ # Definition of functions #
52+ sums = (s1 + s2 + s3 + s4 + s5 )
53+ avg = sums / 5
54+ print ("Your average score =" , avg )
55+
56+ # Conditionals and user output #
57+ if avg >= 90 :
58+ print ("Your grade = A" )
59+ elif avg >= 80 :
60+ print ("Your grade = B" )
61+ elif avg >= 70 :
62+ print ("Your grade = C" )
63+ elif avg >= 60 :
64+ print ("Your grade = D" )
65+ else :
66+ print ("Your grade = F" )
67+
68+ ### Problem 4 ###
69+ # Message to user defining program function and parameters they can select #
70+ print ("To see the breakdown of a month in days, hours, minutes and seconds. "
71+ "Please enter the number of the month." )
72+
73+ print ("1: January" )
74+ print ("2: February" )
75+ print ("3: March" )
76+ print ("4: April" )
77+ print ("5: May" )
78+ print ("6: June" )
79+ print ("7: July" )
80+ print ("8: August" )
81+ print ("9: September" )
82+ print ("10: October" )
83+ print ("11: November" )
84+ print ("12: December" )
85+
86+ # Prompt user for integer selection to represent month #
87+ month = int (input ("Please enter the number of the corresponding month: " ))
88+
89+ # Conditionals and output to user #
90+ if month == 1 :
91+ days = 31
92+ hours = days * 24
93+ minutes = hours * 60
94+ seconds = minutes * 60
95+ print ("January can be expressed in the following units of time:" ,
96+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
97+
98+ elif month == 2 :
99+ leap = input ("Is this a leap year? Enter y/n: " )
100+ if leap == "y" :
101+ days = 29
102+ elif leap == "n" :
103+ days = 28
104+ else :
105+ print ("Enter y/n for: Is this a leap year?" )
106+ hours = days * 24
107+ minutes = hours * 60
108+ seconds = minutes * 60
109+ print ("February can be expressed in the following units of time:" ,
110+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
111+
112+ elif month == 3 :
113+ days = 31
114+ hours = days * 24
115+ minutes = hours * 60
116+ seconds = minutes * 60
117+ print ("March can be expressed in the following units of time:" ,
118+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
119+
120+ elif month == 4 :
121+ days = 30
122+ hours = days * 24
123+ minutes = hours * 60
124+ seconds = minutes * 60
125+ print ("April can be expressed in the following units of time:" ,
126+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
127+
128+ elif month == 5 :
129+ days = 31
130+ hours = days * 24
131+ minutes = hours * 60
132+ seconds = minutes * 60
133+ print ("May can be expressed in the following units of time:" ,
134+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
135+
136+ elif month == 6 :
137+ days = 30
138+ hours = days * 24
139+ minutes = hours * 60
140+ seconds = minutes * 60
141+ print ("June can be expressed in the following units of time:" ,
142+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
143+
144+ elif month == 7 :
145+ days = 31
146+ hours = days * 24
147+ minutes = hours * 60
148+ seconds = minutes * 60
149+ print ("July can be expressed in the following units of time:" ,
150+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
151+
152+ elif month == 8 :
153+ days = 31
154+ hours = days * 24
155+ minutes = hours * 60
156+ seconds = minutes * 60
157+ print ("August can be expressed in the following units of time:" ,
158+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
159+
160+ elif month == 9 :
161+ days = 30
162+ hours = days * 24
163+ minutes = hours * 60
164+ seconds = minutes * 60
165+ print ("September can be expressed in the following units of time:" ,
166+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
167+
168+ elif month == 10 :
169+ days = 31
170+ hours = days * 24
171+ minutes = hours * 60
172+ seconds = minutes * 60
173+ print ("October can be expressed in the following units of time:" ,
174+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
175+
176+ elif month == 11 :
177+ days = 30
178+ hours = days * 24
179+ minutes = hours * 60
180+ seconds = minutes * 60
181+ print ("November can be expressed in the following units of time:" ,
182+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
183+
184+ elif month == 12 :
185+ days = 31
186+ hours = days * 24
187+ minutes = hours * 60
188+ seconds = minutes * 60
189+ print ("December can be expressed in the following units of time:" ,
190+ days , "days," , hours , "hours," , minutes , "minutes," , seconds , "seconds" )
191+
192+ else :
193+ print ("Please enter a valid number" )
194+
195+ ### Problem 5 ###
196+ # Message to user for program function #
197+ print ("Please enter your age in whole years, remainder days, and remainder hours "
198+ "to see the total seconds you've lived" )
199+
200+ # Prompt for user input, assign variables #
201+ years = int (input ("Enter the number of years since your birth: " ))
202+ days = int (input ("Enter the remainder of days: " ))
203+ hours = int (input ("Enter the remainder of hours: " ))
204+ leap = input ("Would you like to factor in leap years? y/n: " )
205+
206+ # Conditionals and user output #
207+ if leap == "y" :
208+ # Approximate leap years as years // 4
209+ leap_days = int (years // 4 )
210+ secondsleap = ((years * 31536000 ) +
211+ (leap_days * 86400 ) +
212+ (days * 86400 ) +
213+ (hours * 3600 ))
214+ print ("Seconds you have lived thus far:" , secondsleap )
215+
216+ elif leap == "n" :
217+ seconds = ((years * 31536000 ) +
218+ (days * 86400 ) +
219+ (hours * 3600 ))
220+ print ("Seconds you have lived thus far:" , seconds )
221+
222+ else :
223+ print ("Enter y/n for: Would you like to factor in leap years?" )
0 commit comments