I am trying to create a calculator program that takes user input and stores it in a list and perform the calculation based on their selection. However, I keep running across an error for line 31 saying
TypeError: 'float' object cannot be interpreted as an integer
.
Here is the code:
import math
def printIntro():
print("This is a simple calculator.")
print("Select an operation:\n1) Add\n2) Subtract\n3) Divide\n4) Multiply")
while True:
operator = input("Enter your choice of + - / *: \n")
if operator in('+', '-', '/', '*'):
#continue asking for numbers until user ends
#store numbers in an array
list = []
num = float(input("What are your numbers?: "))
for n in range(num):
numbers = float(input("What are your numbers?: "))
list.append(numbers)
if n == '':
break
if operator == '+':
print(add(list))
if operator == '-':
print(subtract(list))
if operator == '/':
print(divide(list))
if operator == '*':
print(multiply(list))
else:
break