常用代码

By | 2021 年 5 月 27 日
# 打印楼层,L3-306
for i in range(1,6):
    print(f"------这是第{i}层------")
    for j in range(1,6):
        if i == 4 and j == 4:
            continue
        print(f"L{i}0{j}")
# 打印99乘法表
for i in range(1,10):
    for j in range(1,i+1):
        print(f"{i}X{j}={i*j}", end=" ")
    print()
# 猜年龄
count = 0
while count <5:
    count +=1
    age = 20
    age =int(input("请输入年龄:"))
    if age > 20:
        print("猜大了")
    elif age <20:
        print("猜小了")
    else:
        print("对了")
        break
print("后面的代码")
# 车牌摇号
import random
count = 0
while count <3:
    count += 1
    car_nums = []
    for i in range(5):
        a = random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
        b = "".join(random.sample("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",5))
        c_num=(f"京{a}-{b}")
        print(i+1,c_num)
        car_nums.append(c_num)
    choice = input("请输入:").strip()
    if choice in car_nums:
        print(f"恭喜,{choice}")
        exit("good luck")
    else:
        print("不合法")