Python Programs Written and Practiced by : Jiya Kiyam

File Name : simple_calc.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
"""
Program Name: Simple calculation
Description: Simple calculation among two input numbers
"""

valid = False

while valid == False :
	operation = input("Operations : \n1. Addition \n2. Substraction \n3. Multiplication \n4. Division \nTo operate : ")

	if not operation.isdigit() or int(operation) < 1 or int(operation) > 4 :
		print("Enter a valid option.")
	else :
		valid = True
		
valid = False

while valid == False :
	num1 = input("Enter first number : ")
	if not num1.replace("-", "").isdigit() :
		print("Enter a valid number.")
	else :
		valid = True
		num1 = int(num1)

valid = False

while valid == False :
	num2 = input("Enter second number : ")
	if not num2.replace("-", "").isdigit() :
		print("Enter a valid number.")
	else :
		valid = True
		num2 = int(num2)

if operation == "1" :
	print(f"Sum = {num1 + num2}")
elif operation == "2" :
	print(f"Difference = {num1 - num2}")
elif operation == "3" :
	print(f"Product = {num1 * num2}")
else :
	if num2 == 0 :
		print(f"Quotient = Indefinite")
	else :
		print(f"Quotient = {num1 / num2}")

Run Back to programs