Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 石头剪纸中的圈数选择问题_Python_Python 3.x - Fatal编程技术网

Python 石头剪纸中的圈数选择问题

Python 石头剪纸中的圈数选择问题,python,python-3.x,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

对于这个石头剪刀布游戏,我遇到了一些问题,一个是无法进入比较游戏数量的循环。但在此之前,我没有让它正确地选择一个数字,让计算机选择它抛出的东西。由于我仍在学习如何编码,我希望知道问题是什么

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()
我认为它接近于if c或u的东西。 尝试类似于如果c我想这差不多是c或u的问题了。 尝试类似于如果c如需更多信息,请随时发表评论。祝你好运。

我认为这是可行的,但我仍然有一个问题,那就是计算机选择一个介于1和3之间的随机数,以便与用户输入进行比较。@Warmlawpk441请确保已导入库。从random import randintI我认为这是可行的,但我仍然有一个问题,即计算机选择一个介于1和3之间的随机数,以便与用户输入进行比较。@Warmlawpk441请确保已导入库。从随机导入randint