我的任务是
具有带有播放按钮的开始屏幕。您不必问他们的名字。然后在顶部显示轮号。询问对方的选择(r / p / s)。然后让计算机随机选择。在屏幕上以图形方式显示选择,宣布一轮冠军,然后移至下回合。在屏幕底部永久显示分数。在某人获得3分后宣布获胜者]
我在这里有剪刀石头布的代码`
'导入随机
name =“”
玩家=“”
计算机= 0
Pscore = 0
Cscore = 0
领带= 0
welcome = 0
Round = 0
playagain =“”
def Welcome(): 名称=“”
print("Rules: Rocks beats Scissors, Scissors beats Paper, Paper beats Rock")
print("Its you vs a computer first to 3 wins")
while name == "":
name = input("Whats your name:")
if name != "":
print("Welcome", name)
else:
print("please enter a name without numbers or special charters")
return name
def Choice(): 玩家=“”
while player != "r" and player != "p" and player != "c":
print("Please play one of the following")
player = input(" 1) [R]ock, 2) [P]aper, 3) [S]cissors:")
player = player.lower()
if player == "r":
print("You chose rock")
return 1
elif player == "p":
print("you chose paper")
return 2
elif player == "s":
print("you chose scissors")
return 3
else:
print
"Invalid input, please use capitalized initial (R,P,S)"
def ComputerMoves(): 计算机= random.randint(1,3)
if computer == 1:
print("The computer chose rock")
return 1
elif computer == 2:
print("The computer chose paper")
return 2
else:
print("The computer chose scissors")
return 3
def CompareMoves(p,c): 全球关系 全球Pscore 全球Cscore
if p == c:
print("its a tie!")
tie = tie + 1
elif (p == 1 and c == 3) or (p == 2 and c == 1) or (p == 3 and c == 2):
print("You win the round!")
Pscore = Pscore + 1
elif (p == 1 and c == 2) or (player == 2 and c == 3) or (player == 3 and c == 1):
print("You lose the round!")
Cscore = Cscore + 1
def round(): 全球回合 回合=回合+ 1 print(“ binging round”,Round)
def playerEnd(): 打印(“恭喜您赢得了这场比赛,希望您玩得开心,请确保再次玩过,并向计算机显示谁是老板”)
def computerEnd(): 打印(“计算机这次赢了,再试一次,向他们展示谁是老板”)
def restart(): 全球关系 全球Pscore 全球Cscore 全球回合
name = ""
player = ""
computer = 0
Pscore = 0
Cscore = 0
tie = 0
welcome = 0
Round = 0
playagain = ""
while Pscore < 3 and Cscore < 3:
if playagain == "n" or playagain == "N":
break`enter code here`
if welcome == 0:
name = Welcome()
welcome = welcome + 1
round()
player = Choice()
computer = ComputerMoves()
CompareMoves(player, computer)
print(name + "s", "score is", Pscore)
print("The computers score is", Cscore)
print("You've had", tie, "Ties")
if Pscore == 3:
playerEnd()
if Cscore == 3:
computerEnd()
while playagain != "Y" or playagain != "y" or playagain != "N" or playagain != "n":
print("would you like to play again")
playagain = input("Y/N")
if playagain == "Y" or playagain == "y":
restart()
elif playagain == "N" or playagain == "n":
print("hope you play again")
break
else:
print("please enter Y or N")
enter code here
restart()'`
但是我的问题是我无法使它正常工作,我不知道该怎么做,我尝试观看youtube视频以使开始按钮仍然无法工作,并且我无法显示数字
您甚至还没有制作任何GUI。我不是在这里给您编写程序。它用于询问问题,而不是询问整个代码。只需看看Tkinter module。