python基础练习-猜年龄、编写登陆接口小程序
python基础练习:
一、猜年龄 , 可以让用户最多猜三次!
age=40 count = 1 while count <=3 : user_guess=int(input("input your guess:")) if (user_guess > age): print("try small") elif (user_guess < age): print("try bigger") else: print("you got it!") break count+=1; else: print("笨蛋,你没有尝试了")
![](https://images2015.cnblogs.com/blog/1122835/201703/1122835-20170327155057279-1705194437.png)
二、猜年龄 ,每隔3次,问他一下,还想不想继续玩,y,n
age=40 count = 0 while count >=0: user_guess=int(input("input your guess:")) if (user_guess > age): print("try small") elif (user_guess < age): print("try bigger") else: print("you got it!") break count+=1; if count%3==0: y_or_n=input("do you want to try?(y or n):") if y_or_n =="y": continue else: break
![](https://images2015.cnblogs.com/blog/1122835/201703/1122835-20170327163343951-1743748252.png)
![](https://images2015.cnblogs.com/blog/1122835/201703/1122835-20170327163413623-981909341.png)