Reputation: 79
I have recently started learning Python and tried writing a pomodoro timer program. I have written the tasks()
function and it works fine but i don't know how to write break
function that works together with tasks()
function.
Things I have tried:
I would be really thankful if someone can teach me how to integrate break function with tasks function.
import time
checkmark=0
def 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()
Upvotes: 0
Views: 1181
Reputation: 470
You can define the tasks()
and breaks()
functions as foolows. ALso note that you had not taken any input from the user to carry on with the task or not. You can check the code below. Also I have defined a total_mins
variable which keep tracks of total time worked on the task.
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()
Upvotes: 1