python程序1:猜年龄

判断年龄大小并循环,计算次数

python脚本来无限制猜年龄

age_of_gordon = '39'
guest_count = 0
while guest_count <= 3:
    guest_age = input('Guest age:')
    if guest_age == age_of_gordon:
        print('你猜对了')
        #continue        #退出本次循环
        break              #退出本程序
    elif guest_age > age_of_gordon:
        print('你猜大了')
    else:
        print('你猜小了')
    guest_count += 1
    print('你已经猜了', guest_count, '次')
    if guest_count >=3:
        print("你已经猜了", guest_count, '次,是否还想继续猜?输入y/n')
        if input(guest_age) == 'y':
            guest_count = 0
        else:
            print('你一共猜了', guest_count, '次')
            break
   
posted @ 2019-10-25 13:57  wang509020  阅读(322)  评论(0编辑  收藏  举报