python while循环if_python – 使用if语句时陷入while循环
生活随笔
收集整理的這篇文章主要介紹了
python while循环if_python – 使用if语句时陷入while循环
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我是
python的新手,我正在嘗試做一個簡單的猜數字游戲,我在一個while循環中陷入了一個if語句.這是代碼.
我正在體驗它你的猜測它太高而低一點.我嘗試打破它,但它只是停止了整個事情
def guess_the_number():
number = random.randrange(20)
guessesMade = 0
print('Take a guess')
guess = input()
guess = int(guess)
while guessesMade < 6:
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
print'You got it in', guessesMade, 'guess(es)! Congratulaions!'
else:
print'I\'m sorry, the number was', number
總結
以上是生活随笔為你收集整理的python while循环if_python – 使用if语句时陷入while循环的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++最全输入方式总结(cin、get、
- 下一篇: android 渠道方案,Android