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
19
20
// to help you answer these questions
20
21
21
22
// Questions
22
23
23
24
// a) When formatTimeDisplay is called how many times will pad be called?
24
-
// =============> write your answer here
25
+
// =============> pad will be called 3 times, once for each of the hours, minutes, and seconds values that are being formatted into a string.
25
26
26
27
// Call formatTimeDisplay with an input of 61, now answer the following:
27
28
28
29
// b) What is the value assigned to num when pad is called for the first time?
29
-
// =============> write your answer here
30
+
// =============>Pad is called for the first time with the value of 0, which is the total hours calculated from the input of 61 seconds.
31
+
// The total hours is calculated by dividing the total minutes (1) by 60, which results in 0 hours. pad(totalHours)
30
32
31
-
// c) What is the return value of pad when it is called for the first time?
32
-
// =============> write your answer here
33
+
// c) What is the return value of pad is called for the first time?
34
+
// =============> 0 is the value assigned to num when pad is called for the first time, and the return value of pad is "00". This is because the while loop in the pad function adds a leading zero to the string representation of num until its length is at least 2. Since num is 0, it becomes "00" after one iteration of the loop.
33
35
34
36
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
35
-
// =============> write your answer here
37
+
// =============> pad(remainingSeconds) remainingSeconds =1, so num is +1. This is because the input to formatTimeDisplay is 61 seconds, which results in 1 second remaining after calculating the total minutes and hours. The pad function is called with this value to format it as a two-digit string for display.
36
38
37
39
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
38
-
// =============> write your answer here
40
+
// =============> numString = "1" so string has only one character "01" the return value of pad when it is called for the last time in this program is "01".
41
+
// This is because the while loop in the pad function adds a leading zero to the string representation of num until its length is at least 2.
42
+
// Since num is 1, it becomes "01" after one iteration of the loop.
0 commit comments