ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

第四天,for循环,格式化输出,占位符,pycharm安装.

2019-05-27 16:51:44  阅读:236  来源: 互联网

标签:Salary 格式化 Age 占位 user input print pycharm password


字符格式化输出
占位符 %s s = string
%d d = digit 整数
%f f = float 浮点数,约等于小数

 

Name=input("Input Your Name:")
Age=input("Input Your Age:")
Salary=input("Input Your Salary:")
if Age.isdigit():
Age=int(Age)
else:
print('You must input a number.')
if Salary.isdigit():
Salary=int(Salary)
else :
print('Salary must input with digit.')
msg='''
---------info of %s-----------
Name=%s
Age=%d
Salary=%f
You will retire in %d years.
------------END---------------
'''%(Name,Name,Age,Salary,65-Age)
print(msg)

#for循环
for i in range(3):
  print("loop:",i)
#####range(1,101,2),第一个数表示循环起始值,第二个数为终止值,前包含后不包含,第三个数,步长;
####用户密码验证作业
_user="zoe"
_password="123123"
for i in range(3):
user = input("USER:")
password = input("PassWord:")
if user==_user and password==_password:
print("%s Welcome to login."%_user)
break #####如果break,不执行for循环的else语句
else:
print("Invalid user or password.")
continue
else: #####如果没有break,for循环正常执行完毕,则执行else语句
print("User %s is Blocked." % _user)

########while循环实现3次登陆
_user="zoe"
_password="123123"
counter = 0
while counter<3:
user = input("USER:")
password = input("PassWord:")
if user==_user and password==_password:
print("%s Welcome to login."%_user)
break
else:
print("Invalid user or password.")
counter += 1
if counter == 3:
try_again = input("还想玩吗?[Y/N]:")
if try_again == "Y":
counter = 0
else:
print("User %s is Blocked." % _user)


标签:Salary,格式化,Age,占位,user,input,print,pycharm,password
来源: https://www.cnblogs.com/zpzhou/p/10931514.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有