LZWcc's Blog

Back

第一题:p094扑克排序#

代码:

第二题:多数乘积(可变函数)#

代码:

def func(*nums):
    # 计算所有参数的乘积
    res = 1
    for num in nums:
        res *= num
    return res


# 读入用逗号分隔的数字
arr = list(map(float, input().split(",")))

# 分别输出前 2、3、4 个数的乘积
print(f"前两个数乘积为:{func(*arr[:2]):.1f}")
print(f"前三个数乘积为:{func(*arr[:3]):.1f}")
print(f"前四个数乘积为:{func(*arr[:4]):.1f}")
python

第三题:lambda表达式的使用#

代码:

第四题:金额转换---测试3#

代码:

第五题:逆转裁判#

代码:

第六题:计算某天距元旦的天数#

代码:

from datetime import date

# 读入测试数据组数
n = int(input())

for _ in range(n):
    try:
        # 读入年月日并构造日期对象
        y, m, d = map(int, input().split())
        dd = date(y, m, d)
    except Exception:
        print("ErrorInput")
    else:
        # 计算该日期是当年的第几天
        print("Totaldays =", (dd - date(y, 1, 1)).days + 1)
python

第七题:嵌套列表拆分#

代码:

第八题:Z字形打印#

代码:

Python05函数
https://lzwcc.xyz/blog/pta-python05/
Author LZWcc
Published at May 6, 2026