码迷,mamicode.com
首页 > 其他好文 > 详细

第一章作业

时间:2017-07-24 09:57:00      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:log   lex   ==   got   input   word   class   while   port   

#import getpass


1、猜年龄,可以让用户最多猜三次;

 

 1 age = 56
 2 n = 0
 3 
 4 while n < 3:
 5     guess_age = int(input ("pls input your guess_age(u get three times):"))
 6     n = n + 1
 7     if guess_age > age:
 8         print("pls smaller")
 9     elif guess_age < age:
10         print("pls bigger")
11     else:
12         print("u got it!")

 



 

#每隔三次,问他一下,还想不想继续玩;y,n

 1 age = 56
 2 n = 3
 3 a = 0
 4 while 0 == n%3 :
 5     dis = input("pay or not:")
 6     if dis == "y":
 7         while 1 == 1:
 8             n = n + 1
 9             guess_age = int(input("let‘s start again:"))
10             if guess_age > age:
11                 print("pls smaller")
12             elif guess_age < age:
13                 print("pls bigger")
14             else:
15                 break
16     else:
17         break

 



待完善!

 1 # 输入用户名,密码,认证成功现实欢迎信息;输入三次后锁定;(程序退出,再次输入用户名不能进入;
 2 # 用户记录在文件里面)
 3 import getpass
 4 
 5 
 6 test_times = 3
 7 n = 0
 8 
 9 while n < test_times:
10     n = n + 1
11     user_guess = input("pls input your name:")
12     user_password = getpass.getpass("pls input your password:")
13     if user_guess == "alex" and user_password == "alex123" :
14         print("welcome alex")
15     else:
16         print("u got wrong name or password")

 



第一章作业

标签:log   lex   ==   got   input   word   class   while   port   

原文地址:http://www.cnblogs.com/santizhou/p/7226987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!