我的摇滚,纸张,剪刀游戏中的raw_input函数存在问题

时间:2018-06-07 05:53:40

标签: python python-2.7

我正在创建一个用户正在与计算机对战的摇滚,纸张,剪刀游戏。我试图让它成为程序要求用户从摇滚,纸张或剪刀中选择,如果用户键入除这三个选项之外的任何内容,游戏将要求用户重试并键入一个正确的选项。我试过if else语句和while循环,但都没有用。这是我目前的代码:

# Rock, Paper, Scissors game

import random

options = ['rock', 'paper', 'scissors']

#Computer Choice
computer_choice = random.choice(options)    #assign variable to random

#User Input Function
print "Let's start our match!"
user_choice = raw_input("Do you choose rock, paper, or scissors? : ")
user_choice = user_choice.lower()  #this converts whatever the user types into all lowercase

if user_choice == 'rock' or 'paper' or 'scissors':
    print "The computer chose %s and you chose %s" % (computer_choice, user_choice)
else:
    print("Sorry, please try again")
    user_choice = raw_input("Do you choose rock, paper, or scissors? : ")
    user_choice = user_choice.lower()

#Rock Choice
if user_choice == 'rock':
    if computer_choice == 'rock':
        print "It's a tie."
    elif computer_choice == 'paper':
        print "You lose!"
    else:
        print "You win!!"

#Paper Choice
if user_choice == 'paper':
    if computer_choice == 'rock':
        print "You win!!"
    elif computer_choice == 'paper':
        print "It's a tie."
    else:
        print "You lose!"

#Scissors Choice
if user_choice == 'scissors':
    if computer_choice == 'rock:':
        print "You lose!"
    elif computer_choice == 'paper':
        print "You win!!"
    else:
        print "It's a tie."

提前致谢!

0 个答案:

没有答案