You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python新手求助:代码无报错无输出,月度员工统计功能异常

问题分析与解决

你的代码逻辑完全没问题,之所以没输出,是因为你只调用了函数,但没有打印函数返回的结果。

Python脚本运行时,函数执行后返回的结果如果没有被显式输出(比如用print()),程序不会自动显示内容。

修改后的代码

work_hours = [('sam', 300), ('ream',200), ('deam', 400)]
def employee_check(work_hours):
    current_max = 0
    employee_of_month = ''

    for employee, hours in work_hours:
        if hours > current_max:
            current_max = hours
            employee_of_month = employee
        else:
            pass
    return (employee_of_month, current_max)

# 调用函数并打印结果
result = employee_check(work_hours)
print(result)
# 或者直接一步到位
# print(employee_check(work_hours))

额外说明

如果是在Python交互式环境(比如终端里的Python shell、Jupyter Notebook)中,直接输入employee_check(work_hours)会自动显示返回值,但在普通.py脚本文件里,必须用print()才能让结果输出到控制台。

内容的提问来源于stack exchange,提问作者Dokugan Ryu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 11:02:10