python语法 5 应用guess 之 while else

# -*- coding:utf-8 -*-
# -Author: Paulliam -
# if else 判断;

age_of_yu = 56
guess_count = 0

while guess_count<3:
    guess_age = int(input("guess age:"))
    if guess_age == age_of_yu :
        print("yes, you got it.")  #行首的同级TAB分隔符相当于C语言的花括号
        break  #行首的同级TAB分隔符相当于C语言的花括号
    elif guess_age < age_of_yu:
        print("think smaller...")
    elif guess_age > age_of_yu:
        print("think bigger...")
    guess_count +=1
    if guess_count == 3:
        continue_flag = input("do you want to keep guessing...?")
        if continue_flag != 'n':  #输入字符不是n,则继续循环
            guess_count = 0  # for的循环变量i的值是调整不了的
            print("guess_count was cleared!")
#if 3 == guess_count: #特别用法,该行使用效果等同于下行
else: #相当于while guess_count<3:不成立时执行下面
    print("you have trried too many times! fuck off")
 

##########运行结果:

"D:\Program Files\python-3.6.4\python.exe" C:/Users/Administrator/Desktop/python-prj/guess1.py
guess age:12
think smaller...
guess age:87
think bigger...
guess age:34
think smaller...
do you want to keep guessing...?n
you have trried too many times! fuck off


Process finished with exit code 0



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值