#input的三种格式,.format()
name = input("name:")
age = int (input("age:"))
job = input("job:")
salary = float (input("salary:"))
info1 = '''
name:%s
age:%d
job:%s
salary:%f
'''%(name,age,job,salary)
info2='''
name:{name}
age:{age}
job:{job}
salary:{salary}
'''.format(name = name,age = age,job = job,salary = salary)
info3 = '''
name:{0}
age:{1}
job:{2}
salary:{3}
'''.format(name,age,job,salary)
print(info1,info2,info3)
程序输出结果:
name:zy
age:22
job:IT
salary:20000
name:zy
age:22
job:IT
salary:20000.000000
name:zy
age:22
job:IT
salary:20000.0
name:zy
age:22
job:IT
salary:20000.0
这是第二个程序password暗文输入密码只能在cmd里运行
# _*_ coding:UTF-8 _*_
#@Time:2019/7/621:27
#@Author:ZhouYi
#@Site:
#@File:password.py
#@Software:PyCharm
import getpass
_usename="zhouyi"
_password="123456"
usename = input("usename:")
password = getpass.getpass("password:")
#print(usename,password)
if password==_password and usename==_usename:
print("Welcome User {name} login...".format(name=usename))
else:
print("Invalid Username or Password!")
这是第三个程序猜年龄的每三次提醒一次
# _*_ coding:UTF-8 _*_
#@Time:2019/7/621:54
#@Author:ZhouYi
#@Site:
#@File:guess.py
#@Software:PyCharm
age_of_oldman=56
count=0
while count<3:
guess_age = int(input("guess age:"))
if guess_age==age_of_oldman:
print("yes,you get it")
break
elif guess_age>age_of_oldman:
print("think smaller!")
else:
print("think bigger!")
count+=1
if count==3:
continue_confirm=input("do you want keep guessing")
if continue_confirm=='n':
pass
else:
count=0
else:
print("you have tryed many times...fuck off")