Answer:
The function is as follows:
def tasks(Petyontasks):
timespent = 0
for i, tsk in enumerate(Petyontasks):
if timespent<=10:
timespent+=tsk
else:
break
print("Finish "+str(i)+" tasks in "+str(timespent)+" hours")
Step-by-step explanation:
The program in the question cannot be traced. Hence, the need to begin from scratch.
This defines the function
def tasks(Petyontasks):
This initializes timespent to 0
timespent = 0
This iterates through the tasks [i represents the count of the tasks while tsk represents the time on each task]
for i, tsk in enumerate(Petyontasks):
If timespent is less or equal to 10
if timespent<=10:
The tasks is added and the timespent is calculated
timespent+=tsk
If otherwise
else:
The loop is exited
break
This prints the required output
print("Finish "+str(i)+" tasks in "+str(timespent)+" hours")