Skip to content

Commit cf706e0

Browse files
committed
Init: Added Python foundation projects
0 parents commit cf706e0

File tree

8 files changed

+1216
-0
lines changed

8 files changed

+1216
-0
lines changed

BasicMathOperations.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
################################
2+
# Author: Rahim Siddiq
3+
# Basic Math Operations
4+
################################
5+
6+
# Exercise 1
7+
print("Hello, World")
8+
9+
name = input("please enter your name: ")
10+
print("Welcome Mr.", name)
11+
12+
rooms = int(input("How many rooms?: "))
13+
price = float(input("Select price per room: "))
14+
print("Price per room is", price)
15+
print("Number of rooms reserved:", rooms)
16+
17+
price = price + (price * 10 / 100)
18+
total = rooms * price
19+
print("Total price after 10% tax:", total)
20+
21+
# Problem 1
22+
print("Please enter two numbers to be added together")
23+
x = int(input("Enter first number: "))
24+
y = int(input("Enter second number: "))
25+
sum = x + y
26+
print(x, "+", y)
27+
print("Sum:", sum)
28+
29+
# Problem 2
30+
print("Difference Calculator")
31+
print("Please enter two numbers")
32+
x = int(input("Enter first number: "))
33+
y = int(input("Enter second number to be subtracted from first: "))
34+
diff = x - y
35+
print(x, "-", y)
36+
print("Difference:", diff)
37+
38+
# Problem 3
39+
print("Please enter two numbers to be multiplied")
40+
x = int(input("Enter first number: "))
41+
y = int(input("Enter second number: "))
42+
mult = x * y
43+
print(x, "*", y)
44+
print(mult)
45+
46+
# Problem 4
47+
print("Please enter two numbers to be divided")
48+
x = int(input("Enter first number: "))
49+
y = int(input("Enter second number to divide the first: "))
50+
div = x / y
51+
print(x, "/", y)
52+
print(div)
53+
54+
# Problem 5
55+
print("Exponential Calculator")
56+
print("Please enter two numbers, the first will be raised to the power of the second")
57+
x = int(input("Enter first number: "))
58+
y = int(input("Enter second number: "))
59+
exp = x ** y
60+
print(x, "**", y)
61+
print(exp)
62+
63+
# Problem 6
64+
print("Remainder division")
65+
print("Please enter two numbers, the first will be divided by the second and will find any remainders")
66+
x = int(input("Enter first number: "))
67+
y = int(input("Enter second number: "))
68+
divr = x % y
69+
print(x, "/", y)
70+
print("Remainder:", divr)
71+
72+
# Problem 7
73+
print("Whole integer division")
74+
print("Please enter two numbers, the first will be divided by the second, result rounded down to whole number")
75+
x = int(input("Enter first number: "))
76+
y = int(input("Enter second number: "))
77+
divw = x // y
78+
print(x, "/", y)
79+
print(divw)
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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?")

MenuBasedCalculator.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
################################
2+
# Author: Rahim Siddiq
3+
# Menu Based Calculator
4+
################################
5+
6+
def add(): # Function Add
7+
return n1 + n2
8+
9+
def subtract(): # Function Subtract
10+
return n1 - n2
11+
12+
def multiply(): # Function Multiply
13+
return n1 * n2
14+
15+
def divide(): # Function Divide
16+
return n1 / n2
17+
18+
def remainder(): # Function Modulus / Remainder
19+
return n1 % n2
20+
21+
def integer_division(): # Function Integer Division
22+
return n1 // n2
23+
24+
def exponentiation(): # Function Exponentiation
25+
return n1 ** n2
26+
27+
def average(): # Function Average
28+
return sum(a) / n
29+
30+
print("Please select the number of the function you wish to calculate:")
31+
print("1.Add")
32+
print("2.Subtract")
33+
print("3.Multiply")
34+
print("4.Divide")
35+
print("5.Remainder")
36+
print("6.Integer_Division")
37+
print("7.Exponentiation")
38+
print("8.Average")
39+
40+
cfunction = input("Enter Number of The Function: ")
41+
42+
if cfunction in ("1","2","3","4","5","6","7"):
43+
n1 = float(input("Enter first number: "))
44+
n2 = float(input("Enter second number: "))
45+
46+
if cfunction == "1":
47+
print(n1, "+", n2, "=", add())
48+
49+
elif cfunction == "2":
50+
print(n1, "-", n2, "=", subtract())
51+
52+
elif cfunction == "3":
53+
print(n1, "*", n2, "=", multiply())
54+
55+
elif cfunction == "4":
56+
if n2 == 0:
57+
print("Error: cannot divide by zero")
58+
else:
59+
print(n1, "/", n2, "=", divide())
60+
61+
elif cfunction == "5":
62+
if n2 == 0:
63+
print("Error: modulus by zero is undefined")
64+
else:
65+
print(n1, "%", n2, "=", remainder())
66+
67+
elif cfunction == "6":
68+
if n2 == 0:
69+
print("Error: integer division by zero")
70+
else:
71+
print(n1, "//", n2, "=", integer_division())
72+
73+
elif cfunction == "7":
74+
print(n1, "**", n2, "=", exponentiation())
75+
76+
elif cfunction == "8":
77+
n = int(input("How many numbers would you like to average? "))
78+
if n < 1:
79+
print("Please enter a value of at least 1.")
80+
else:
81+
a = []
82+
for i in range(n):
83+
val = float(input("Enter a number: "))
84+
a.append(val)
85+
print("Values entered", list(a), "Average:", average())
86+
87+
else:
88+
print("Please select the number of the function you would like to perform.")

0 commit comments

Comments
 (0)