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
21
// to help you answer these questions
20
22
21
23
// Questions
22
24
23
25
// a) When formatTimeDisplay is called how many times will pad be called?
24
-
// =============> write your answer here
26
+
// =============> Pad is called 3 times.
25
27
26
28
// Call formatTimeDisplay with an input of 61, now answer the following:
27
29
28
30
// b) What is the value assigned to num when pad is called for the first time?
29
-
// =============> write your answer here
31
+
// =============> 0 is the value assigned to num as the first pad is totalhours which calculates to be 0
30
32
31
33
// c) What is the return value of pad is called for the first time?
32
-
// =============> write your answer here
34
+
// =============> "00" - this is because it has been stated within the function that if the value's length is less than 2 which 0 is, then add another 0 at the beginning ("0" + numString;). Also toString converts 0 from a number to a string which is why I included ""
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
+
// =============> the last pad is remainingSeconds which is 1 so the value assigned to num is 1
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
+
// =============> "01" - same logic as quested c. Also as "01" is not shorter than length of 2 the loop closes and doesn't run again
0 commit comments