Crossin的编程教室

标题: 为什么循环无法结束 [打印本页]

作者: 东东哥    时间: 2018-10-19 17:19
标题: 为什么循环无法结束
a=False
while a==False:
    from random import choice

    score=[0,0]
    direction=['left','right','center']

    print'Shooting ball games!'
    for i in range(5):
        print'---- Round %d - You Kick! ----'%(i+1)
        print'choose one side to shoot'
        print'left right center'
        you=raw_input()
        if (you=='left')or(you=='right')or(you=='center'):
            print 'you kicked' + you
            com=choice(direction)
            print 'computer saved'+com
            if you!=com:
                print'Goal!'
                score[0]+=1
            else:
                print'Oops...'
        else:
            print'Your input is incorrect.\nWarning, computer score!'
            score[1]+=1
        print'Score: %d(you) - %d(com)\n' %(score[0],score[1])

        print'---- Round %d - You Save! ----'%(i+1)
        print'choose one side to save'
        print'lefe center right'
        you=raw_input()
        if (you=='left')or(you=='right')or(you=='center'):
            print'you saved'+you
            com=choice(deirection)
            print'computer kicked'+com
            if you==com:
                print'Savde!'
            else:
                print'Oops...'
                score[1]+=1
        else:
            print'Your input is incorrect.\nWarning, computer score!'
            score[1]+=1
        print'Score: %d(you) - %d(com)\n' %(score[0],score[1])

    if score[0]>=score[1]:
        if score[0]>score[1]:
            print'You win!'
        else:
            print'The game has drawn!'
    else:
        print'You lose!'

    print'\nIf you want to continue the game, please enter 1.\nExit input 0'

    b=input()
    if b==('1'):
        a=True








作者: 风扇很响    时间: 2018-10-19 20:33
最后是不是写反了
1继续,0退出
那就应该是
if b==('0'):
        a=True
作者: 东东哥    时间: 2018-10-19 20:37
风扇很响 发表于 2018-10-19 20:33
最后是不是写反了
1继续,0退出
那就应该是

b=input()
    if b ==1:
        print'Game restarts\n'
    else:
        a=True
        print'Game over\n'
嗯嗯,我改为这样可以了,




欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/) Powered by Discuz! X2.5