gpt4 book ai didi

python - 剪刀石头布 - 平局时如何开始新游戏

转载 作者:行者123 更新时间:2023-11-28 21:47:22 25 4
gpt4 key购买 nike

<分区>

我真的是 Python 编码的新手,而且由于我是基础知识,所以每个代码实际上都是一大堆乱七八糟的代码。我现在想做的是石头剪子布蜥蜴史波克游戏,稍后会转化为视觉游戏,希望能成为我手机的基本应用程序,以提高我的学习能力,无论如何,这是代码。

我想做的是,当玩家和计算机平局时,询问用户是否想再玩一次,我无法正确解决,我将不胜感激。

import random

computerChoice = random.randint(1,5)
playerChoosing = True
answer = True

if computerChoice == 1:
computerChoice = "rock"
elif computerChoice == 2:
computerChoice = "paper"
elif computerChoice == 3:
computerChoice = "scissors"
elif computerChoice == 4:
computerChoice = "spock"
elif computerChoice == 5:
computerChoice = "lizard"

while playerChoosing == True:
print("rock, paper, scissors, lizard, spock, What do you choose?")
playerChoice = input()
if playerChoice == "rock":
print("you chose rock")
playerChoosing = False
elif playerChoice == "paper":
print("you chose paper!")
playerChoice = "paper"
playerChoosing = False
elif playerChoice == "scissors":
print("you chose scissors!")
playerChoice = "scissors"
playerChoosing = False
elif playerChoice == "lizard":
print("you chose lizard!")
playerChoice = "lizard"
playerChoosing = False
elif playerChoice == "spock":
print("you chose spock!")
playerChoice = "spock"
playerChoosing = False
else:
print("this is not an option, please try again")
playerChoosing = True

input()

print("The computer chose: " +computerChoice+ "!")

input()
#lose


while answer == True:
if playerChoice == "rock" and computerChoice == "paper":
print("you lose!, the rock was covered by the paper!")
elif playerChoice == "paper" and computerChoice == "scissors":
print("you lose!, scissors cut the paper in half")
elif playerChoice == "scissors" and computerChoice == "rock":
print("you lose!, rock crushed the scissors")
elif playerChoice == "spock" and computerChoice == "lizard":
print("you lose!, lizard poisons spock")
elif playerChoice == "scissors" and computerChoice == "spock":
print("you lose!, spock smashes scissors")
elif playerChoice == "rock" and computerChoice == "spock":
print("you lose!, spock vaporizes the rock")
elif playerChoice == "paper" and computerChoice == "lizard":
print("you lose!, lizard eats paper")
elif playerChoice == "lizard" and computerChoice == "rock":
print("you lose!, rock crushes lizard")
elif playerChoice == "lizard" and computerChoice == "scissors":
print("you lose!, scissors kills lizard")
elif playerChoice == "spock" and computerChoice == "paper":
print("you lose!, paper disproves spock")
#win
elif playerChoice == "paper" and computerChoice == "rock":
print("you win!, the rock was covered by the paper!")
elif playerChoice == "scissors" and computerChoice == "paper":
print("you win!, scissors cut the paper in half!")
elif playerChoice == "rock" and computerChoice == "scissors":
print("you win!, rock crushed the scissors!")
elif playerChoice == "lizard" and computerChoice == "spock":
print("you win!, lizard poisons spock!")
elif playerChoice == "spock" and computerChoice == "scissors":
print("you win!, spock smashes scissors!")
elif playerChoice == "lizard" and computerChoice == "paper":
print("you win!, lizard eats paper!")
elif playerChoice == "rock" and computerChoice == "lizard":
print("you win!, rock crushes lizard!")
elif playerChoice == "scissors" and computerChoice == "lizard":
print("you win!, scissors kills lizard!")
elif playerChoice == "paper" and computerChoice == "spock":
print("you win!, paper disproves spock!")
elif playerChoice == "spock" and computerChoice == "rock":
print("you win!, spock vaporizes rock!")
#draw
elif playerChoice == "paper" and computerChoice == "paper":
print("It's a draw, want to try again?, please type YES or NO: ")
answer = input()
if answer == "yes":
answer = False
else:
break
elif playerChoice == "rock" and computerChoice == "rock":
print("It's a draw, want to try again?, please type YES or NO: ")
answer = input()
if answer == "yes":
answer = False
else:
break
elif playerChoice == "scissors" and computerChoice == "scissors":
print("It's a draw, want to try again?, please type YES or NO: ")
answer = input()
if answer == "yes":
answer = False
else:
break
elif playerChoice == "lizard" and computerChoice == "lizard":
print("It's a draw, want to try again?, please type YES or NO: ")
answer = input()

elif playerChoice == "spock" and computerChoice == "spock":
print("It's a draw, want to try again?, please type YES or NO: ")
answer = input()

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com