You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
15
15
// to help you answer these questions
16
16
17
17
// Questions
18
18
19
19
// a) When formatTimeDisplay is called how many times will pad be called?
20
20
// =============> write your answer here
21
+
// Three times.
21
22
22
23
// Call formatTimeDisplay with an input of 61, now answer the following:
23
24
24
25
// b) What is the value assigned to num when pad is called for the first time?
25
26
// =============> write your answer here
27
+
/* The first time pad() runs, it's used for the fours part of the time.
28
+
Because 61 seconds equals 0 hours, the value given to num is 0 /*
26
29
27
30
// c) What is the return value of pad is called for the first time?
28
31
// =============> write your answer here
29
32
33
+
/* The first time pad() runs, it's formatting the hours part of the time.
34
+
Since the hours value is 0, it turns that into the string "00" by adding a leading zero before returning it /*
35
+
30
36
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
31
37
// =============> write your answer here
38
+
/* When the function runs with 61 seconds, the last time pad() is called is for the second part of the time. Since 61 seconds has 1 seconds has 1 second left
39
+
over after making a full minute, the value passed into pad() is 1. Inside the function, num equals 1, and it gets turned into "01" so the final time shows as 00:01:01 */
32
40
33
41
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
34
42
// =============> write your answer here
43
+
/* When pad() is called for the last time, num is 1 because there's 1 second left over.
44
+
The function turns that number into the string "01" by adding a leading zero. That "01" is the value that gets returned and used as the seconds part of the final time display (00:01:01) */
0 commit comments