current position:Home>In Python, the condition setting and interpretation of while loop

In Python, the condition setting and interpretation of while loop

2022-02-03 00:28:23 CSDN Q & A

The phenomenon and background of the problem

while True: In condition settings ,True Of T Can you use lowercase letters ? This True Conditions , When to jump out of the loop

>>> import random>>> import easygui as eg>>> eg.msgbox(" Welcome to the world of guessing numbers !!!")'OK'>>> eg.msgbox(" Welcome to the world of guessing numbers !!!",ok_button = " continue ")' continue '>>> da = random.randint(1,100)>>> m = eg.integerbox(msg = " Please input your guess number ",title = " Take a guess ",lowerbound = 1,upperbound = 100)>>> while True:    if da == m:        eg.msgbox(" That's right , Are you the roundworm in my stomach ?")        eg.msgbox(" hum ! There is no reward for guessing right !")    else:        if da > m:            eg.msgbox(" The small , The small ")        else:            eg.msgbox(" big , big ")    m = eg.integerbox(msg = " Please enter the number you guessed again ",title = " Take a guess ",lowerbound = 1,upperbound = 100)>>>eg.msgbox(" Game over , Don't play !!")
Operation results and error reporting contents
My solution ideas and tried methods
What I want to achieve



Refer to the answer 1:

Add one break Dropped out

import randomimport easygui as egeg.msgbox(" Welcome to the world of guessing numbers !!!")'OK'eg.msgbox(" Welcome to the world of guessing numbers !!!", ok_button=" continue ")' continue 'da = random.randint(1, 100)m = eg.integerbox(msg=" Please input your guess number ", title=" Take a guess ", lowerbound=1, upperbound=100)while True:    if da == m:        eg.msgbox(" That's right , Are you the roundworm in my stomach ?")        eg.msgbox(" hum ! There is no reward for guessing right !")        break    else:        if da > m:            eg.msgbox(" The small , The small ")        else:            eg.msgbox(" big , big ")    m = eg.integerbox(msg=" Please enter the number you guessed again ", title=" Take a guess ", lowerbound=1, upperbound=100)eg.msgbox(" Game over , Don't play !!")



Refer to the answer 2:



Refer to the answer 3:

python in True and False Is the key word , Valid in uppercase , Lowercase is not a variable name .




Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030028202697.html

Random recommended