import random
#Rock Paper Scisscors Lizard Spock Game
#Name to number
rock =()
paper =()
scisscors =()
lizard =()
Spock =()
def main():
print("Let's play rocker, paper, scissors, lizard, Spock")
computer = npc_guess()
player = user_guess()
complete(computer, player)
def user_guess(): #Users hand in RPSLS
player = input("Choose 'rock', 'paper', 'scisscors', 'lizard', 'Spock'")
game = True
while game:
if player == 'rock' or player == 'paper' or player == 'scisscors'\
or player == 'lizard' or player == 'Spock':
return player
else:
print("That Choice isn't valid.")
user_guess()
def npc_guess(): #computers hand in RPSLS
while True:
computer = random.randrange(0, 4)
if computer == 0:
print("The NPC has chosen rock")
computer == rock
elif computer == 1:
print("The NPC has chosen paper")
computer == paper
elif computer == 2:
print("The NPC has chosen scisscors")
computer == scisscors
elif computer == 3:
print("The NPC has chosen lizard")
computer == lizard
elif computer == 4:
print("The NPC has chosen Spock")
computer = Spock
return computer
npc_guess()
def complete(player, computer): #determines if the computer beat you, if not you win or tie.
if computer == ('rock' and player == 'lizard') or (computer == 'rock' and player == 'paper')\
or (computer == 'paper' and player == 'scisscors') or (computer == 'paper' and player == 'Spock')\
or (computer == 'scisscors' and player == 'paper') or (computer == 'paper' and player == 'lizard')\
or (computer == 'lizard' and player == 'paper') or (computer == 'lizard' and player == 'Spock')\
or (computer == 'Spock' and player == 'rock') or (computer == 'Spock' and player == 'scisscors'):
print("The Computer wins")
elif computer == player:
print("It was a tie")
else:
print("You win!")
main()
幾個問題,我找不出來。沒有我選擇的和NPC選擇的東西,它總是說用戶是贏家。當我運行程序時,它還要求我連續兩次選擇一個選項。創建一個python搖滾紙剪刀遊戲,有一些bug
你不能只是解釋兩句傾倒你的整個代碼在這裏,並希望有人來下載,運行它,並把它擦亮你... –
刪除函數調用你剛過函數定義有。 – hjpotter92
創建一個帶有五個鍵(電腦手)的字典,兩個vals是失手(玩家)。它會讓你的代碼更清潔 – SirParselot