クラスの 1 つのプログラムを完成させようとしていますが、無効な構文が表示され続けます。Python は私にとって非常に新しいので、私の無知に耐えてください。
「ifguess==(num_x+num_y):」のコロンで無効な構文がポップアップしています。
update* かっこを修正しました abarnert に感謝しますが、今では次のようになりましたSyntaxError
Traceback (most recent call last):
File "C:\Users\Franz\Desktop\randomstudy.py", line 48, in <module>
main()
File "C:\Users\Franz\Desktop\randomstudy.py", line 25, in main
guess=int(input(num_x, "-", num_y, "=\n"))
TypeError: input expected at most 1 arguments, got 4
以下のコードを更新して、括弧を含めました。
def main():
import random
num_x=random.randint(-50,50)
num_y=random.randint(-50,50)
op=random.randint(0,3)
control=True
print("Welcome! Here is your random problem:\n")
if op==0:
while True:
guess=int(input(num_x, "+", num_y, "=\n"))
if guess==(num_x+num_y):
print("Congratulations! You have answered the problem correctly!")
break
else:
print("I’m sorry, that is not correct. Please try again.")
elif op==1:
while True:
guess=int(input(num_x, "-", num_y, "=\n"))
if guess==(num_x-num_y):
print("Congratulations! You have answered the problem correctly!")
break
else:
print("I’m sorry, that is not correct. Please try again.")
elif op==2:
while True:
guess=int(input(num_x, "*", num_y, "=\n"))
if guess==(num_x*num_y):
print("Congratulations! You have answered the problem correctly!")
break
else:
print("I’m sorry, that is not correct. Please try again.")
elif op==3:
while True:
guess=int(input(num_x, "/", num_y, "=(Please round to two decimal places)\n"))
if guess==(num_x/num_y):
print("Congratulations! You have answered the problem correctly!")
break
else:
print("I’m sorry, that is not correct. Please try again.")
main()