Skip to content

Commit 49e833b

Browse files
Update main.py
1 parent 95b56d2 commit 49e833b

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

main.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
import subprocess #import library
1+
formulas = {
2+
'average speed': 'Average Speed.py',
3+
'acceleration': 'Acceleration.py',
4+
'density': 'Density.py',
5+
'force': "Newton's Second Law.py",
6+
'power': 'Power.py',
7+
'weight': 'Weight.py',
8+
'pressure': 'Pressure.py',
9+
'kinetic energy': 'Kinetic Energy.py',
10+
"ohm's law": "Ohm's Law.py",
11+
'frequency': 'Frequency.py'
12+
}
213

3-
choice = input("What you want to calculate : ").casefold() #user choices which calculation he/she wants to do.
4-
5-
6-
if choice == "average speed":
7-
subprocess.call(["python", "Formulas/Average Speed.py"]) #Calls Average Speed Formula
8-
if choice == "acceleration":
9-
subprocess.call(["python", "Formulas/Acceleration.py"]) #Calls Acceleration Formula
10-
if choice == "density":
11-
subprocess.call(["python", "Formulas/Density.py"]) #Calls Density Formula
12-
if choice == "force":
13-
subprocess.call(["python", "Formulas/Newton's Second Law.py"]) #Calls Weight Formula
14-
if choice == "power":
15-
subprocess.call(["python", "Formulas/Power.py"]) #Calls Power Formula
16-
if choice == "weight":
17-
subprocess.call(["python", "Formulas/Weight.py"]) #Calls Weight Formula
18-
if choice == "pressure":
19-
subprocess.call(["python", "Formulas/Pressure.py"]) #Calls Pressure Formula
20-
if choice == "kinetic energy":
21-
subprocess.call(["python", "Formulas/Kinetic Energy.py"]) #Calls Kinetic Energy Formula
22-
if choice == "ohm's law":
23-
subprocess.call(["python", "Formulas/Ohm's Law.py"]) #Calls Ohm's Law Formula
24-
if choice == "frequency":
25-
subprocess.call(["python", "Formulas/Frequency.py"]) #Calls Frequency Formula
14+
while True:
15+
choice = input("What you want to calculate, or enter 'exit' to quit: ").casefold()
16+
if choice == 'exit':
17+
break
18+
try:
19+
exec(open(f"Formulas/{formulas[choice]}").read())
20+
except KeyError:
21+
print("Invalid choice. Please select a valid formula.")

0 commit comments

Comments
 (0)