所以我遇到了這個遊戲的問題,當我運行這個程序時,不管用戶輸入哪個號碼,他們總是會輸。任何人都看到問題?選擇與隨機存在問題。 Python
#python project, rock paper scissors game that responds to the user
#must use if, while, for, list, be 50 lines long
import random
from random import choice
winList = []
rock, paper, scissors = 1, 2, 3
choiceOptions = [1, 2, 3]
startOver = input("Do you want to play rock paper scissors?")
startOver = startOver.lower()
while startOver == "yes":
name = input("What is your name?")
print("What's good, ", name, ", welcome to the rock paper scissors game!")
userChoice = input("It's your go! Rock(1), paper(2), or scissors(3)?")
compChoice = choice(choiceOptions)
#if userChoice != "1" or userChoice != "2" or userChoice != "3":
#print("That's not a valid choice, please choose a number from 1-3")
if compChoice == userChoice:
print("You tied! No-one is the wiser!")
elif userChoice == 1 and compChoice == 3:
print ("You win! The computer chose ", compChoice)
winList.append(str(1))
if userChoice == 2 and compChoice == 3:
print ("You win! The computer chose ", compChoice)
winList.append(str(1))
if userChoice == 2 and compChoice == 1:
print ("You win! The computer choice ", compChoice)
if userChoice == 3 and compChoice == 2:
print ("You win! The computer chose ", compChoice)
winList.append(str(1))
print ("You've won ", winList, "times!")
else:
print ("You lose, try again! The computer chose ", compChoice)
謝謝!男人,調試可以讓人難以置信。 :) –