Python控制流语句(if,while,for)

if.py

number=23
guess=int(input("enter an int:"))
if guess==number:
    print ("congratulations, you guessed it.")
elif guess<number:
    print ("No, it's a little higher than that")
else:
    print ("No, it's a little lower than that")

print ("done")

while.py

number=23
running=True

while running:
    guess=int(input("input an integer:"))
    if guess==number:
        print("congs, you guessed it")
        running=False
    elif guess>number:
        print ("No, it's a little higher")
    else:
        print ("No, it's a little lower")
else:
    print("the while loop is over.")
print ("done")

for.py

for i in range(1,10):
    print (i)
else:
    print ("the for loop is over")

break.py

while True:
    s = input('Enter something : ')
    if s == 'quit':
        break
    print ('Length of the string is', len(s))
print ('Done')

continue.py

while True:
    s=input('enter something:')
    if s=='quit':
        print ('you are quit from program')
        break
    if len(s)<3:
        print ('input is',s)
        continue
    print ('input is of sufficient length')
print ('the program is over')
原文地址:https://www.cnblogs.com/oskb/p/5065826.html