在使用python 3.7的简单脚本方面需要帮助

时间:2019-03-09 19:43:46

标签: python

我正在用python 3.7做一个简单的剪刀石头布项目。无论我选择什么,我似乎都无法赢。如果我选择纸张或岩石,似乎总是选择纸张,而如果我选择剪刀,则似乎总是选择岩石。我对此还很陌生,因此我需要针对这种特定情况的答案。谢谢

import random
while 1 >= 0:
    rps = random.randint(1,4)
    if rps == 1:
        rps == "rock"
    elif rps == 2:
        rps == "paper"
    else:
        rps == "scissors"
    userchoice = input("Rock, paper, or scissors? Use r for rock, p for paper, and s for scissors. ")
    if userchoice == 'r' or 'R' and rps == "paper":
        print ("The cpu chose paper, you lose.")
    elif userchoice == 'S' or 's' and rps == "paper":
        print ("The cpu chose paper, you win!")
    elif userchoice == 'p' or 'P' and rps == "paper":
        print ("The cpu chose paper, you tied.")
    elif userchoice == 'r' or 'R' and rps == "rock":
        print ("The cpu chose rock, you tied.")
    elif userchoice == 'p' or 'P' and rps == "rock":
        print ("The cpu chose rock, you win!")
    elif userchoice == 's' or "S" and rps == "rock":
        print ("The cpu chose rock, you lose.")
    elif userchoice == 'r' or 'R' and rps == "scissors":
        print ("The cpu chose scissors, you win!")
    elif userchoice == 'p' or 'P' and rps == "scissors":
        print ("The cpu chose scissors, you lose.")
    elif userchoice == 's' or 'S' and rps == "scissors":
        print ("The cpu chose scissors, you tied.")
    restart = input("type r to restart. ")
    if restart == 'r' or 'R':
        continue
    else:
        break

0 个答案:

没有答案