用户登录验证
#!/usr/bin/env python# -*- coding:utf-8 -*-#首先定义一个明文的用户名和密码用于之后的比对_username = 'seven_day'_password = '123456'username = input("username:")password = input("password:")#用if来判断_username和输入的username变量内容,如果输入的内容=之前定义的内容则打印Welcome,如果输入错误则打印Invalidif _username == username and _password == password: print("Welcom user {name} login...".format(name=username))else: print("Invalid print username or password")
猜年龄
#!/usr/bin/env python# -*- coding:utf-8 -*-#判断输入的值是否跟age_of_lin 匹配,并分别输入大于小于或等于的结果。#首先定义一个变量用于之后作比较age_of_lin = 31guess_age = int(input("guess_age:")) #输入数字默认不会被识别,需要把str转换成int数字if guess_age == age_of_lin: print("YES,you got it!")#如果if判断的条件不成立,继续elif判断下一个条件elif guess_age > age_of_lin: print("Try smaller....")else: print("Try bigger!")