The use and circulation of input in python

The use and circulation of input in python

#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)

Program output:
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
This is the second program password cipher text input password can only be run in 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!")

This is every third reminder for the third program to guess the age

# _*_ 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")

Guess you like

Origin blog.csdn.net/qq_44089890/article/details/94914089