Skip to content

Commit 48f6610

Browse files
committed
Add "Simple Calculator" example
Signed-off-by: Ercan Ersoy <ercanersoy@ercanersoy.net>
1 parent 704f273 commit 48f6610

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Copyright (c) 2020 Ercan Ersoy
88

99
* [Hello World](hello-world)
1010
* [User Input](user-input)
11-
* [Circle Calculator](circle-calculator)
11+
* [Circle Calculator](circle-calculator)
12+
* [Simple Calculator](simple-calculator)
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
while True:
2+
print("1. Addition")
3+
print("2. Substraction")
4+
print("3. Multiplication")
5+
print("4. Division")
6+
print("5. Exit")
7+
choice = input("Your choice: ")
8+
9+
if choice == "1":
10+
first_addend = float(input("First addend: "))
11+
second_addend = float(input("Second addend: "))
12+
print("Result: ", end="")
13+
print(first_addend + second_addend)
14+
elif choice == "2":
15+
first_subtrahend = float(input("First subtrahend: "))
16+
second_subtrahend = float(input("Second subtrahend: "))
17+
print("Result: ", end="")
18+
print(first_subtrahend - second_subtrahend)
19+
elif choice == "3":
20+
multiplier = float(input("Multiplier: "))
21+
multiplicand = float(input("Multiplicand: "))
22+
print("Result: ", end="")
23+
print(multiplier * multiplicand)
24+
elif choice == "4":
25+
dividend = float(input("Dividend: "))
26+
divider = float(input("Divider: "))
27+
print("Result: ", end="")
28+
print(dividend / divider)
29+
elif choice == "5":
30+
break
31+
else:
32+
print("Wrong choice!")
33+
34+

0 commit comments

Comments
 (0)