python中input的使用与循环

python中input的使用与循环

#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")
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值