小编use*_*425的帖子

python while循环的麻烦

我很抱歉,如果这是一个荒谬的问题,但我只是在学习python,我无法弄清楚这一点.:)

我的程序应该打印用户输入的任何州的资本.有时它会连续工作十次,有时会连续工作三次,然后它会在你输入状态后停止.如果我重新启动它并键入它停止的状态它将工作正常....随机次数然后它将再次停止.我究竟做错了什么?我的代码也很可怕吗?我不知道要使用什么样的代码,所以我只是想把它放在任何可以工作的东西上.

    x = str(raw_input('Please enter a sate: ' ))
    while x == 'Alabama':
        print 'Montgomery is the capital of', x
        x = str(raw_input('Please enter a state: '))
    while x ==  'Alaska':
        print 'Juneau is the capital of', x
        x = str(raw_input('Please enter a state: '))                  
    while x == 'Arizona':
        print 'Phoenix is the capital of', x
        x = str(raw_input('Please enter a state: ' ))
    while x == 'Arkansas':
        print 'Little Rock is the capital of', x
        x = str(raw_input('Please …
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
199
查看次数

标签 统计

python ×1