设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 9074|回复: 2
打印 上一主题 下一主题

为什么循环无法结束

[复制链接]

6

主题

0

好友

166

积分

注册会员

Rank: 2

跳转到指定楼层
楼主
发表于 2018-10-19 17:19:41 |只看该作者 |倒序浏览
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







回复

使用道具 举报

2

主题

0

好友

476

积分

中级会员

Rank: 3Rank: 3

沙发
发表于 2018-10-19 20:33:30 |只看该作者
最后是不是写反了
1继续,0退出
那就应该是
if b==('0'):
        a=True
回复

使用道具 举报

6

主题

0

好友

166

积分

注册会员

Rank: 2

板凳
发表于 2018-10-19 20:37:43 |只看该作者
风扇很响 发表于 2018-10-19 20:33
最后是不是写反了
1继续,0退出
那就应该是

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

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-4-25 23:31 , Processed in 0.024339 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部