游戏需要这些功能,它可以工作,但它不会显示胜利者 . 因为这是明天晚上到期的结果 . 它今天被分配给我 . 我已尽力而为,而且我根本不知道该做些什么 .
该游戏由计算机随机挑选 1
至 3
. 1
正在摇滚, 2
是纸, 3
是剪刀 . 计算机选择不会显示't need to be displayed in the beginning. Then the user is supposed to enter in either rock paper or scissors. After that the computer' . 根据石头剪刀的基本规则选择胜利者 . 如果两个球员都有相同的答案,则认为是平局 .
而对于我的成绩,它必须具有 main()
, get_ComputerMove()
, get_PlayerMove()
和 calculateWinner()
的功能 . 谢谢 .
import random
def startAgain():
randomNumber = getRandomNumber()
computerChoice = get_ComputerMove(randomNumber)
userChoice = get_PlayerMove()
print('The computer chose', computerChoice )
winner, message = calculateWinner(computerChoice,userChoice )
if winner != 'no winner':
print(winner,'won(',message, ')')
def getRandomNumber():
randomNumber = random.randint( 1, 3 )
return randomNumber
def get_ComputerMove( randomNumber ):
if randomNumber == 1:
computerChoice = "rock"
elif randomNumber == 2:
computerChoice = "paper"
else:
computerChoice = "scissors"
return computerChoice
def get_PlayerMove():
userChoice = input("Please enter your choice")
return userChoice
def calculateWinner( computerChoice, userChoice ):
rockMessage = "The rock smashes the scissors"
scissorsMessage = "Scissors cuts paper"
paperMessage = "Paper covers the rock"
winner = "no winner"
message = ""
if computerChoice == "rock" and userChoice == "scissors":
winner = "Computer"
message = rockMessage
elif computerChoice == "scissors" and userChoice == "rock":
winner = "you"
message = rockMessage
if computerChoice == "scissors" and userChoice == "paper":
winner = "Computer"
message = scissorsMessage
elif computerChoice == "paper" and userChoice == "scissors":
winner = "you"
message = scissorsMessage
if computerChoice == "paper" and userChoice == "rock":
winner = "Computer"
message = paperMessage
elif computerChoice == "rock" and userChoice == "paper":
winner = "you"
message = paperMessage
return winner, message
def main():
randomNumber = getRandomNumber()
computerChoice = get_ComputerMove(randomNumber)
userChoice = get_PlayerMove()
print("The computer chose" , computerChoice )
winner,message = calculateWinner( computerChoice,userChoice )
if winner != "no winner":
print(winner,"won(",message, ")")
while winner == "no winner":
print('You both chose the same thing')
winner = startAgain()
main()
1 回答
如果你想 repeat 游戏 until 它有一个胜利者, while loop 哎呀: