Rock Paper Scissors中的循环和数字选择问题

时间:2017-10-09 15:26:15

标签: python python-3.x

对于这种石头剪刀游戏,我遇到了一些问题,一个是它未能进入比较游戏数量的循环。但在此之前,我没有让它为计算机正确选择一个数字来选择它所引发的内容。由于我还在学习如何编码,我很高兴知道问题是什么

from random import randint

def rock_paper_scissors():
    w = int(input('How many rounds to win? '))
    u = int(0)
    c = int(0)
    r = int(1)
    if c or u < w:
        print ('Round #', r)
        ut = input('Do you throw Rock (1), Paper (2), or Scissors (3)? ')
        ct = randint(1, 3)
        print ('Computer threw', ct)
        if ut == ct:
            print (Tie)
            print ('Score:'
                   'Computer:', c,
                   'User:', u)             
        if ut == 1 and ct == 2:
            print ('Computer wins')
            c += 1
            r =+ 1
            print ('Score:'
                   'Computer:', c,
                   'User:', u)
        if ut == 1 and ct == 3:
            print ('You win')
            u +=1
            r +=1
            print ('Score:'
                   'Computer:', c,
                   'User:', u)            
        if ut == 2 and ct == 1:
            print ('You win')
            u += 1
            r += 1
            print ('Score:'
                   'Computer:', c,
                   'User:', u)             
        if ut == 2 and ct == 3:
            print ('Computer wins')
            c += 1
            r += 1
            print ('Score:'
                   'Computer:', c,
                   'User:', u)             
        if ut == 3 and ct == 1:
            print ('Computer wins')
            c += 1
            r +=1
            print ('Score:'
                   'Computer:', c,
                   'User:', u)             
        if ut == 3 and ct == 2:
            print ('You win')
            u += 1
            r += 1
            print ('Score:'
                   'Computer:', c,
                   'User:', u)             
    if c == w:
        print ('Computer wins')
    if u == w:
        print ('You win')

def main(): 
    print('ROCK PAPER SCISSORS in Python')
    print()
    print('Rules: 1) Rock wins over Scissors.')
    print('       2) Scissors wins over Paper.')
    print('       3) Paper wins over Rock.')

    rock_paper_scissors()

main()

1 个答案:

答案 0 :(得分:0)

我认为它靠近if c or u的东西。 尝试类似if c < w or u < w:的内容 请随时评论以获取更多信息。祝你好运。