Skip to content

Commit 039c7b8

Browse files
authored
Create main.py
1 parent 7f80162 commit 039c7b8

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

day97/main.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import time
2+
3+
4+
def clear_screen():
5+
clear = "\n" * 100
6+
print(clear)
7+
8+
9+
def percent_of_num():
10+
print("You chose option #1 - What is x % of y?\n")
11+
x = float(input("What is the value of x?: "))
12+
y = float(input("What is the value of y?: "))
13+
answer = f"\n{x} is {(x * y) / 100}% of {y}\n"
14+
print(answer)
15+
another_calc()
16+
17+
18+
def num_percent_of_num():
19+
print("You chose option #2 - x is what % of y?\n")
20+
x = float(input("What is the value of x?: "))
21+
y = float(input("What is the value of y?: "))
22+
answer = f"\n{x} is {(x * 100) / y}% of {y}"
23+
print(answer)
24+
another_calc()
25+
26+
27+
def percent_num_to_num():
28+
print("You chose option #3 - What is the % increase/decrease from x to y?\n")
29+
x = float(input("What is the value of x?: "))
30+
y = float(input("What is the value of y?: "))
31+
if x > y:
32+
answer = f"\nThere is a -{((x - y) / x) * 100}% difference between {x} and {y}"
33+
else:
34+
answer = f"\nThere is a +{((y - x) / x) * 100}% difference between {x} and {y}"
35+
print(answer)
36+
another_calc()
37+
38+
39+
def another_calc():
40+
response = input("\nWould you like to perform another calculation? (Y/N): ")
41+
if response == "Y" or response == "y":
42+
clear_screen()
43+
main()
44+
elif response == "N" or response == "n":
45+
clear_screen()
46+
print("Thanks for using the Percentage Calculator!")
47+
else:
48+
clear_screen()
49+
print("Choose a valid answer!\n")
50+
time.sleep(2)
51+
clear_screen()
52+
another_calc()
53+
54+
55+
def main():
56+
print("Types of calculations:\n")
57+
print("1. What is x % of y?\n"
58+
"2. x is what % of y?\n"
59+
"3. What is the % increase/decrease from x to y?\n")
60+
61+
choice = input("Select a calculation from 1-3: ")
62+
if choice == "1":
63+
clear_screen()
64+
percent_of_num()
65+
elif choice == "2":
66+
clear_screen()
67+
num_percent_of_num()
68+
elif choice == "3":
69+
clear_screen()
70+
percent_num_to_num()
71+
else:
72+
clear_screen()
73+
print("Choose a valid answer!\n")
74+
time.sleep(2)
75+
clear_screen()
76+
main()
77+
78+
79+
print("Welcome to the Percentage Calculator!\n")
80+
main()

0 commit comments

Comments
 (0)