【Python】格式化输出、猜随机数、ASCII码加密、加减乘除测试题
# 格式化输出常用方式
length,weight = 159,50
print("length:%d cm,weight:%f kg"%(length,weight))
import math
print("{0:>+10.2f}".format(math.pi))# +3.14
print(f"pi is {math.pi:>+10.2f}")# pi is +3.14
#随机数猜大小
import random
key = random.randint(1,100)# 随机数
i = 3
while i>0:
num = int(input("请输入一个整数(1-100)"))
if num <= 1 or num >= 100:
print("请重新输入")
elif num == key:
print("猜对了")
break
elif num > key:
print("大了")
共有 0 条评论