-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
50 lines (50 loc) · 1.42 KB
/
test.py
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
def welcome():
print("welcome.")
def calculate():
num1 = eval(input("Enter your first_number: "))
num2 = eval(input("Enter your second_number:"))
operation = input("""
type in the operator to use:
+ for addition
- for subtraction
* for multiplication
/ for division
** for exponention
// for floor division
% for modulus
""")
if operation == "+":
sum = num1 + num2
print("{} + {} = ".format(num1,num2),sum)
elif operation == "-":
subtraction = num1 - num2
print("{} - {} = ".format(num1,num2),subtraction)
elif operation == "*":
multiplication = num1 * num2
print("{} * {} = ".format(num1,num2),multiplication)
elif operation == "/":
division = num1 / num2
print("{} / {} = ".format(num1,num2),division)
elif operation == "**":
num3 = eval(input("Enter the power = "))
exponent = num1 **num3
print("{} ** {} = ".format(num1,num3),exponent)
elif operation == "%":
modulus = num1/num2
print("{} % {} = ".format(num1,num2),modulus)
else:
print("check your operator.")
repeat()
def repeat():
response = input("""
Do you want to continue?
press y for yes and n for no.
""")
if response == "y":
calculate()
elif response == "n":
welcome()
else:
repeat()
welcome()
calculate()