用python制作石头、布、剪刀代码。SyntaxError:编译单个语句时发现多个语句

2024-05-18 16:16:27 发布

您现在位置: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()

我不知道为什么它不起作用它告诉我的一切

SyntaxError:编译单个语句时发现多个语句。你知道吗

有人能帮忙吗?谢谢。你知道吗

哦,我还在3.6.0上运行python


Tags: tonoyouinputifexitprogramyes
1条回答
网友
1楼 · 发布于 2024-05-18 16:16:27
  • 在while循环中,您正在进行赋值,而不是比较,请将=更改为==

  • 每次使用fudge()时,结尾都会出现引号缺失的情况。

  • 最后,您得到了if batman == "no"它应该在的地方if batman == "no":(注意两点)。

相关问题 更多 >

    热门问题