第二组眼睛会有所帮助

时间:2018-03-20 07:31:15

标签: python

非常感谢第二眼看到这段代码因某种原因它永远不会通过输入函数。所以其他块不运行..

#!/usr/bin/env python
import random

# import pdb ; pdb.set_trace()


def main():
    print('_' * 40)
    print('       Guessing Game. ')
    print('_' * 40)
    print()

    print("guess a number between 1 & 100")
    ranNum = random.randint(1, 100)
    found = False
    while not found:
        guess = int(input('please enter a guess:\n'))
    if guess == ranNum:
        print('you win!')
        found = True
    elif guess > ranNum:
        print('guess lower\n')
    else:
        print('guess higher')

if __name__ == "__main__":
    main()

2 个答案:

答案 0 :(得分:1)

谢谢你所有问题都是块的缩进。

while not found:
    guess = int(input('please enter a guess:\n'))
    if guess == ranNum:
        print('you win!')
        found = True
    elif guess > ranNum:
        print('guess lower\n')
    else:
        print('guess higher'

答案 1 :(得分:0)

if guess == ranNum:
    print('you win!')
    found = True
elif guess > ranNum:
    print('guess lower\n')
else:
    print('guess higher')
<{1>}循环中的