Home > Article > Backend Development > Detailed explanation of the use of while and if in python3
This article explains in detail the use of while and if in python3. Friends in need can refer to it.
# Auther: Aaron Fan age_of_oldboy = 56 #定义一个while循环的起始判断值count count = 0 #当count小于3的情况下一直执行while循环 while count < 3: guess_age = int(input("猜一下oldboy的年纪: ")) if guess_age == age_of_oldboy: print("好的,你猜对了") #满足条件后退出循环break,break是结束整个循环 break #当前面一条if或者elif不成立的情况下, 才会执行后面的elif elif guess_age > age_of_oldboy: print("猜大了...") #所有if不成立的情况下才会执行else else: print("猜小了!") #没执行玩一次while,就给count的值加1 count += 1 #当while条件里面的东西执行执行完了,就会执行下面的else,如果中间被break了,就不会再执行下面的else了 else: print("你用尽了所有的机会...")
The above is the detailed content of Detailed explanation of the use of while and if in python3. For more information, please follow other related articles on the PHP Chinese website!