用Python制作石头,纸,剪刀代码.语法错误:编译单个语句时发现多个语句



这是我的代码:

import random
import time
validInput = False

computer = (random.choice(["rock", "paper", "scissors"]))
batman = input("welcome to rock, paper, scissors would you like to play: yes or no?"
if batman == "yes":
choice = input("okay, these are the rules: I will say, rock, paper, scissors, shoot and then I will ask you what you picked and then tell you who won - are you ready to play: yes or no?")
if choice == "yes":
while validInput = False:
time.sleep(1)
print("rock")
time.sleep(1)
print("paper")
time.sleep(1)
print("scissors")
time.sleep(1)
print("shoot")
time.sleep(1)
what = input("what did you pick")
if what == "rock" and computer == "rock":
print("I picked rock too, I guess we drawed")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
if what == "rock" and computer == "paper":
print("I picked paper, so I guess I won better luck next time")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
if what == "rock" and computer == "scissors":
print("I picked scissors, I guess you win")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
if what == "paper" and computer == "paper":
print("I picked paper, so I guess we drawed")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
if what == "paper" and computer == "scissors":
print("I picked scissors, so I guess I won better luck next time")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
if what == "paper" and computer == "rock":
print("I picked rock, so I guess you won")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
if what == "scissors" and computer == "scissors":
print("I picked scissors, so I guess we drawed")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
if what == "scissors" and computer == "rock":
print("I picked rock, so I guess I won better luck next time")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
if what == "scissors" and computer == "paper":
print("I picked paper, so I guess you won")
fudge = input("do you want to play again: yes or no?)
if fudge == "yes":
print("restarting program")
continue
if fudge == "no":
print("okay, terminating program")
exit()
else:
print("invalid input, terminating program")
exit()
else:
chicken = input("invalid input, do you want to try again: yes or no?")
if chicken == "yes":
print("restarting now")
invalidInput = False
continue
if chicken == "no":
print("okay, terminating program")
invalidInput = True
exit()
else:
print("invalid input, terminating program")
invalidInput = True
exit()

if choice == "no":
print("okay terminating program")
invalidInput = True
exit()
else:
print("invalid input, terminating program")
exit()
if batman == "no"
print("okay, terminating program")
exit()
else:
print ("invalid input, terminating program")
exit()

我不知道为什么它不起作用,它告诉我的是

语法错误:编译单个语句时发现多个语句。

有人可以帮忙谢谢。

哦,我也在 3.6.0 上运行 python

  • 在 while 循环中,您正在进行分配,而不是比较,将=更改为==

  • 每次使用fudge()末尾都会缺少引号。

  • 最后,您if batman == "no"了应该if batman == "no":的位置(请注意两点(。

最新更新