-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (32 loc) · 1011 Bytes
/
main.py
File metadata and controls
36 lines (32 loc) · 1011 Bytes
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
def open_calculator():
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
operator = input("Select an operator (+, -, * or /): ")
if operator == "+":
result = num1 + num2
print("\nAnswer: " + str(result) + "\n")
open()
elif operator == "-":
result = num1 - num2
print("\nAnswer: " + str(result) + "\n")
open()
elif operator == "*":
result = num1 * num2
print("\nAnswer: " + str(result) + "\n")
open()
elif operator == "/":
if num2 == 0:
print("You cannot divide by 0!")
open()
else:
result = num1 / num2
print("\nAnswer: " + str(result) + "\n")
open()
def open():
print("Welcome to the calculator!\n")
user_input = input("Press 'c' to contiue or press 'e' to exit: ")
if user_input == "c":
open_calculator()
elif user_input == "e":
print("Goodbye!")
open()