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

字符格式化输出
占位符 %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)


猜你喜欢

转载自www.cnblogs.com/zpzhou/p/10931514.html
今日推荐