+ 2

Help me please, code error

while True: print('options:') print('addition: a') print('substraction: b') print('multiply: c') print('divide: d') input=(input(': ')) if input=='end': break elif input=='a': a = float(input("Enter a number: ")) b =float(input("Enter a number: ")) c =str(a+b) print('answer is : '+c) elif input=='b': a=float(input('Enter a number')) b=float(input('enter a number')) c=a-b print('answer is : '+c) elif input=='c': a=float(input('enter a number')) b=float(input('enter a number')) c=a*b print('answer is : '+c) elif input=='d': a=float(input('enter a number')) b=float(input('enter a number')) c=a/b print('answer is : '+c) else: print('unknown input') I get this error: Traceback (most recent call last): File "ifprogram.py", line 12, in <module> a = float(input("Enter a number: ")) TypeError: 'str' object is not callable I tried to google it bud no help there, I am new to python and have no idea what can be wrong. Thank you for help.

9th Jun 2017, 5:54 PM
dominik
dominik - avatar
3 Respuestas
+ 7
I delete my wrong answer to avoid it confuses others
9th Jun 2017, 6:23 PM
seamiki
seamiki - avatar
+ 3
The problem is that input (the variable) is the same name as the input function. Change input = (input(': ')) To: userInput = (input(': ')) Or something like that, then fix the if statements to match that name. Works fine for me with that fix. You can't have same named things in Python, whether it be a function or variable. This is because when you say input = ...; you're re-assigning input from a function to some string. Note* most other languages don't work this way.
9th Jun 2017, 6:09 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
Thank you so much,i am good to go now
9th Jun 2017, 6:20 PM
dominik
dominik - avatar