| ???? Python ??? | ??6?? ?????? | |
|---|---|---|
| ???? | while??? | ???? |
???????????????????¡ê?while?????????????????????while???????¦Í ??? ????????????while?????????????else???
#!/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.'
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'
????????code/while.py??
$ python while.py
Enter an integer : 50
No, it is a little lower than that.
Enter an integer : 22
No, it is a little higher than that.
Enter an integer : 23
Congratulations, you guessed it.
The while loop is over.
Done
??????????§µ??????????????????????????????????????????????????????????????????????????????????????????????????????????¦Â2??????????????????????????????while??????¨¢?
?????raw_input??if????????while????????????while?????????running?????????True?????????????????running????True???????§Ü???? while-?? ????????????????????¦Ì???????????????????§µ???????running???????????????????????????while-?ï…?????????????§á????else-?ï…?????????????????
??while??????????False?????else??????§³??????????????????????????¦Á????????????while????????else?????????????§µ????????while???????????????????????
True??False???????????????????????????§¹???????1??0??????????????????????????????????????????????????1??
else??????????????????????????§Ö??????????ð‹??while??????§µ?????while??????????????????????§¹????
??C/C++??????????
????????????while???????????else???
| ???? | ????? | ???? |
|---|---|---|
| if??? | ??? | for??? |