-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject_10.py
More file actions
38 lines (34 loc) · 1.24 KB
/
Copy pathProject_10.py
File metadata and controls
38 lines (34 loc) · 1.24 KB
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
from art import logo10
def calculation(num1, num2, operator):
if operator == '+':
return num1 + num2
elif operator == '-':
return num1 - num2
elif operator == '*':
return num1 * num2
elif operator == '/':
return num1 / num2
else:
return 'Invalid operator'
def calculator():
print(logo10)
num1 = float(input('Enter the first number: '))
continue_calculation = True
while continue_calculation:
num2 = float(input('Enter the second number: '))
operator = input("Enter a operator ('+','-','*','/'): ")
if num2 == 0 and operator == '/':
print('Cannot divide by zero')
continue_calculation = False
result = calculation(float(num1), float(num2), operator)
if result == 'Invalid operator':
print('Invalid operator')
continue_calculation = False
print(f'{num1} {operator} {num2} = {result}')
user_choice = input(f"Type 'y' to continue calculating with {result}, or type 'n' to start a new calculation: ").lower()
if user_choice == 'y':
num1 = result
else:
continue_calculation = False
calculator()
calculator()