第一章作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一章作业相关的知识,希望对你有一定的参考价值。
#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")
以上是关于第一章作业的主要内容,如果未能解决你的问题,请参考以下文章