第二天杂记

格式化字符串:
 %s  格式化字符串

 %d  格式化整数

 %f  格式化浮点数

多个格式化字符串 需要在%后面加上() 用,分开 例:

fruit = input("想吃什么水果")
money = int(input("有多少钱"))
#
# %s 字符串
# %d 数字
# %f 浮点数


print("我想吃%s,我有%d钱"%(fruit,money))
#如果想在格式化输出中表示单纯的%,需要在后面加上一个%号

#运算符:
#and 优先级比 or 高

 #非零转换成bool 值 就是True

  print(bool(-1))#T

  print(bool(0))#F

  print(1 and 2) #2

  print(0 or 2)# 2

  print(0 or 4 and 3 or 2) 例: 先算 4 and 3 为3 然后 0 or 3 返回3 然后 3 or 4 返回3

  print(2 or 1 < 3 and 2)# 数字 or True 返回数字 数字在前

  print(2 > 1 or 3) # True #True在前面

 

  思考题:
    print(1 > 2 and 3 or 4 and 3 < 2) # 1>2 看做一个整体返回False FALSE and 3->3为True, False and True 为Falese,右边同理

 

  

i = 3
while i >= 0:
userName = input("请输入用户名")
i -= 1
if userName == "a":
print("用户名正确")
pwd = int(input("请输入密码"))
if pwd == 123:
print("登录成功")
break
else:
print("密码错误,你还有%d次机会"%i)
continue

else:
if i == 0:
print("机会用完")
break
else:
print("用户名错误,你还有%d次机会"%i)
incomplete format 格式化错误

 

猜你喜欢

转载自www.cnblogs.com/huasongweb/p/9492754.html
今日推荐