さて、今日は基本的な電卓を作成しました (そして、今日はプログラミングを学ぶ最初の日です)。次のコードでこのエラーが発生します。
Traceback (most recent call last):
File "C:\Users\Stone\Desktop\unfinished calculator.py", line 42, in <module>
start()
File "C:\Users\Stone\Desktop\unfinished calculator.py", line 26, in start
n1()
TypeError: 'int' object is not callable
これをコードとして
x = 1
global n1
global n2
global opp1
def n1():
global n1
n1 = input("Number to perform operation on: ")
n1 = int(n1)
def n2():
global n2
n2 = input("Number to perform operation with: ")
n2 = int(n2)
def opp():
global opp1
opp1 = input("Available operations to perform with number:\n1)Addition\n2)Subtraction\n3)Multiplication\n4)Division\n5)Exit Calculator\nPlease enter number choice (1-5): ")
opp1 = int(opp1)
def add():
print(n1 + n2)
def subtract():
print (n1 - n2)
def multiply():
print(n1 * n2)
def divide():
print(n1 / n2)
def start():
n1()
opp()
n2()
if opp1 == 1:
add()
elif opp1 == 2:
subtract()
elif opp1 == 3:
multiply()
elif opp1 == 4:
divide()
elif opp1 == 5:
x = 0
else:
print("Invalid Choice!")
while x == 1:
start()
誰かがここで何が悪いのか説明してもらえますか?