在我运行的每个打印语句的末尾都会打印“无”。我不完全清楚为什么?

2024-10-06 07:50:15 发布

您现在位置:Python中文网/ 问答频道 /正文

def finished_projects(unfinished_projects, completed_projects):
    while unfinished_projects:
        current_project = unfinished_projects.pop()
        print('completing project: ' + current_project)
        completed_projects.append(current_project)

def show_completed_projects(completed_projects):
    print('\nThese projects have been completed:')
    for project in completed_projects:
        print(project)
    

unfinished_projects = ['pie-chart', 'bar graph', 'line chart']
completed_projects = []

print(finished_projects(unfinished_projects,completed_projects))
print(show_completed_projects(completed_projects))

Tags: projectdefshowchartcurrentpopprojectsprint
2条回答

这是因为您正试图打印两个函数的返回值,而这两个函数都没有,请尝试执行以下操作:

finished_projects(unfinished_projects,completed_projects)
show_completed_projects(completed_projects)

调用函数时,不要添加打印。只需调用函数即可

def finished_projects(unfinished_projects, completed_projects):
    while unfinished_projects:
        current_project = unfinished_projects.pop()
        print('completing project: ' + current_project)
        completed_projects.append(current_project)

def show_completed_projects(completed_projects):
    print('\nThese projects have been completed:')
    for project in completed_projects:
        print(project)
    

unfinished_projects = ['pie-chart', 'bar graph', 'line chart']
completed_projects = []

finished_projects(unfinished_projects,completed_projects)
show_completed_projects(completed_projects)

如果您返回一些内容,则可以使用打印

相关问题 更多 >