为了账号安全,请及时绑定邮箱和手机立即绑定

Python 中的番茄钟计时器

Python 中的番茄钟计时器

胡说叔叔 2022-12-20 12:24:10
我最近开始学习Python并尝试编写一个番茄钟程序。我已经编写了tasks()函数并且它工作正常但我不知道如何编写与函数break一起工作的tasks()函数。我尝试过的事情:我尝试编写与 tasks() 函数分开的 break 函数,并在 tasks() 函数中调用 break 函数。我已经在 tasks() 函数中编写了中断代码。在其中定义主要功能和书面中断功能,但没有任何效果。我试过用谷歌搜索但找不到答案。如果有人能教我如何将中断功能与任务功能集成在一起,我将非常感激。import timecheckmark=0def tasks():    global checkmark    carry_on='y'    while carry_on=='y'or carry_on=='Y':        min=0        task=input('What task do you want to work on?')        print('timer for ',task,' is 25 mins')        start=input('Press Enter to start the timer.')        while min!=1:            time.sleep(60)            min=min+1        print('End of task')        checkmark=checkmark+1        print('Total check mark is ',checkmark)def main():    tasks()    mins=0    if checkmark <4:        print('take a short break')        while mins!=3:            time.sleep(60)            mins=mins+1            print('break over')    elif checkmark >=4:        print('Take a long break')        while mins !=10:            time.sleep(60)            mins=mins+1        print('Break over')    else:        tasks()if __name__ == '__main__':    main()
查看完整描述

1 回答

?
翻过高山走不出你

TA贡献1875条经验 获得超3个赞

您可以将tasks()和breaks()函数定义为傻瓜。另请注意,您没有从用户那里获取任何输入来决定是否继续执行任务。您可以检查下面的代码。我还定义了一个total_mins变量,用于跟踪完成任务的总时间。


import time


checkmark = 0

total_mins = 0


def tasks(task):

    global checkmark

    global total_mins

    mins=0

    print('Timer for ',task,' is 25 mins.')

    start=input('Press Enter to start the timer.')

    while mins <= 25:

        time.sleep(60)

        mins = mins + 1

        total_mins += 1

        print(mins, " minutes work completed.")

    print('End of Pomodoro')

    checkmark += 1

    print('Total check mark is ',checkmark)



def breaks():

    global checkmark

    mins = 0

    if checkmark <4:

        print('Take a short break.')

        while mins!=3:

            time.sleep(60)

            mins = mins + 1

            print(mins, " minutes break completed.")

        print('Break over')


    elif checkmark >=4:

        print('Take a long break.')

        while mins !=10:

            time.sleep(60)

            mins = mins + 1

            print(mins, " minutes break completed.")

        checkmark = 0

        print('Break over.')



def main():

    carry_on = 'y'

    task=input('Welcome to Pomodoro Timer\n What task do you want to work on? ')

    while carry_on=='y'or carry_on=='Y':

        tasks(task)

        breaks()

        carry_on = input("Do you want ot carry on?(y/n)")


    print("End of task ",task,". \nTotal time worked was minutes ", total_mins, " minutes.")


if __name__ == '__main__':

    main()


查看完整回答
反对 回复 2022-12-20
  • 1 回答
  • 0 关注
  • 91 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号