-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_calculator.py
More file actions
33 lines (28 loc) · 1009 Bytes
/
Copy pathsimple_calculator.py
File metadata and controls
33 lines (28 loc) · 1009 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
# -*- coding: utf-8 -*-
"""Simple Calculator.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/13iMeXQcJI7lZRhIWAUSxCSw7cXnUwCwR
"""
# Simple calculator with function
def calculator():
while True:
decision = input("Do you want to continue (yes/no): ")
if decision.lower() == "no":
break
num1 = int(input("Enter first value: "))
num2 = int(input("Enter second value: "))
operator = input("Enter operator you want to perform (+, -, *, /): ")
if operator == "+":
print("Result is:", num1 + num2)
elif operator == "-":
print("Result is:", num1 - num2)
elif operator == "*":
print("Result is:", num1 * num2)
elif operator == "/":
if num2 != 0:
print("Result is:", num1 / num2)
else:
print("You can't divide by 0!")
else:
print("Invalid operator!")