I've written a simple code to run calculator.
It's still in development stage, not yet completed.
I see that the code is not running on sublime text 3 where am running python 3.6.4.
In fact, the code is falling in an infinite loop. But this is not the case in online compilers.
Source code
while True:
print("Welcome to calculator")
print("Pick an option from the below,")
print("1.Add 2.Subtract 3.Divide 4.Multiply 5.Quit")
user_input = int(input())
if(user_input == 1):
print("!!!Addition of numbers!!!")
print("Provide atleast 2 numbers to add : ")
numbers_arr = []
while True:
numbers = float(input())
numbers_arr.append(numbers)
if(len(numbers_arr) >= 2):
print("1.Add 2.insert more numbers")
option = int(input())
if(option == 1):
result = sum(numbers_arr)
print("Addition of numbers is : {}".format(result))
break
elif(option == 2):
numbers = float(input())
numbers_arr.append(numbers)
else:
print("Invalid option idiot!")
numbers_arr=[]
break
else:
continue
if(user_input == 2):
print("!!!Subtraction of numbers!!!")
numbers_arr = []
while True:
numbers = float(input())
numbers_arr.append(numbers)
if(len(numbers_arr) >= 2):
print("1.Subtract 2.insert more numbers")
option = int(input())
if(option == 1):
result = 0
for i in numbers_arr[::-1]:
result = i - result
print("Subtraction of numbers is : {}".format(result))
break
elif(option == 2):
numbers = float(input())
numbers_arr.append(numbers)
else:
print("Invalid option idiot!")
break
else:
continue
if(user_input==5):
break
Output on Online compiler (repl.it,onlinegdb)
Welcome to calculator
Pick an option from the below,
1.Add 2.Subtract 3.Divide 4.Multiply 5.Quit
1
!!!Addition of numbers!!!
Provide atleast 2 numbers to add :
12
2
1.Add 2.insert more numbers
1
Addition of numbers is : 14.0
Welcome to calculator
Pick an option from the below,
1.Add 2.Subtract 3.Divide 4.Multiply 5.Quit
Output on Sublime text 3
Welcome to calculator
Pick an option from the below,
1.Add 2.Subtract 3.Divide 4.Multiply 5.Quit
1
10
78@
23516
.
.
.
Any suggestions in improving the code for calculator will be appreciated. Thank you!