-1

如果用户猜对了数字,我正在尝试使变量number增加!如果被其他用户猜到,则继续增加增加的值。但似乎我syntax错了。所以我真的需要你的帮助。贝娄是我的代码:

#!/usr/bin/python
# Filename: while.py
number = 23
running = True

while running:
    guess = int(raw_input('Enter an integer : '))

    if guess == number:
        print 'Congratulations, you guessed it. The number is now increase'
        number += 1 # Increase this so the next user won't know it!
        running = False # this causes the while loop to stop
    elif guess < number:
        print 'No, it is a little higher than that.'
    else:
        print 'No, it is a little lower than that.'
else:
    print 'The while loop is over.'
    # Do anything else you want to do here
print 'Done'
4

2 回答 2

1

你可以在没有“运行”变量的情况下做到这一点,它不是必需的

#!/usr/bin/python
# Filename: while.py
number = 23
import sys

try:
    while True:
        guess = int(raw_input('Enter an integer : '))
        if guess == number:
            print('Congratulations, you guessed it. The number is now increase')
            number += 1 # Increase this so the next user won't know it!
        elif guess < number:
            print('No, it is a little higher than that.')
        else:
            print('No, it is a little lower than that.')
except ValueError:
    print('Please write number')
except KeyboardInterrupt:
    sys.exit("Ok, you're finished with your game")
于 2012-12-23T13:17:45.033 回答
-1
#!/usr/bin/python
# Filename: while.py
number = 23
running = True

while running:
    guess = int(raw_input('Enter an integer : '))

    if guess == number:
        print 'Congratulations, you guessed it. The number is now increase'
        number += 1 # Increase this so the next user won't know it!
        running = False # this causes the while loop to stop
    elif guess < number:
        print 'No, it is a little higher than that.'
    else:
        print 'No, it is a little lower than that.'

# Do anything else you want to do here
print 'Done'
于 2012-12-23T13:05:59.257 回答