# 2.14. Timed Exam¶

A timed exam can have a time limit or can just show how much time the learner has taken. The timed exam can give feedback after the exam is taken or not.

You can include several different types of questions in a timed exam, but it is best to separate questions that should be centered like writing code questions from the left-justified questions like multiple-choice questions.

The following example keeps track of the time used, but does not have a time limit. It is from the Student CSP ebook. It can be seen by clicking on the following link Timed-Exam-Unlimited.

2-11-1: What will be the values in x, y, and z after the following lines of code execute?

```x = 7;
y = 5;
z = 0;
z = x;
x = y;
y = z;
```
• x = 7, y = 5, z = 0
• Those are the original values, but they change.
• x = 5, y = 7, z = 7
• x is set to 7 but changed to the value of y which is 5. y is set to 5 originally, but is changed to the value of z but after z has been set to the value of x which is 7. z was set to 0 originally but changes to the the value of x which is 7.
• x = 5, y = 7, z = 0
• This would be true if setting y to z reset z to 0, but that is not what happens.
• x = 5, y = 5, z = 7
• y was set to 5 originally, but the value was changed.
• I don't know
• That is okay. We do not expect you to know this.

2-11-2: What is the output from the program below?

```denominator = 4
if denominator == 0:
print ("Mere mortals cannot divide by zero.")
else:
print (1000 / denominator)
```
• Mere morals cannot divide by zero.
• The sentence prints only if denominator is equal to 0, but it is not.
• 1000 / 4
• It will print the result of the division.
• 250.0
• It only prints the result of dividing 1000 by 4 which is 250.0.
• Mere mortals cannot divide by zero. 250.
• The sentence prints only if denominator is equal to 0, but it is not.
• I don’t know
• That is okay. We do not expect you to know this.

2-11-3: What is the output from the program below?

```def check_systolic(num1):
if num1 < 120:
return 0
elif num1 < 140:
return 1
elif num1 < 180:
return 2
else:
return 3

def check_diastolic(num2):
if num2 < 80:
return 0
elif num2 < 90:
return 1
elif num2 < 110:
return 2
else:
return 3

syst = 135
dias = 100
if check_systolic(syst) == 0 and check_diastolic(dias) == 0:
print ("Normal")
elif check_systolic(syst) == 3 or check_diastolic(dias) == 3:
print ("Hypertensive Crisis")
elif check_systolic(syst) == 1:
if check_diastolic(dias) > 1:
print ("High Blood Pressure A")
else:
print ("Prehypertension")
```
• Normal
• This will only print when both check_systolic and check_diastolic return 0 which is when check_systolic is passed a number less than 120 and check_diastolic is passed a number less than 80.
• Hypertensive Crisis
• This will only print when either check_systolic or check_diastolic return 3 which is when check_systolic is passed a number greater or equal to 180 and check_diastolic is passed a number greater than or equal to 110.
• High Blood Pressure A
• This will print when check_systolic was 1 and check_diastolic was greater than 1 (but not 3).
• Prehypertension
• This will print when check_systolic was 1 and check_diastolic was less than or equal to 1.
• I don’t know
• That is okay. We do not expect you to know this.

The following is an example where there is a time limit. It comes from the Java Review ebook. See the original by clicking on the following Timed-Exam.

2-11-4: Given the following method. What is the output when `m1(5)` is called?

```public int m1 (int a)
{
if (a == 1)
return 10;
else
return 10 + m1 (a – 1);
}
```
• 50
• This is a recursive method. It will return 10 when a is equal to 1, otherwise it will do a recursive call. Each call adds 10.
• 20
• This would be true if the call was m(2).
• 60
• This would be true if the call was m(6).
• 10
• This would be true if the call was m(1).
• 30
• This would be true if the call was m(3).

2-11-5: What will the following code print when it is executed?

```for (int j = 1; j <= 3; j++) {
for (int k = 1; k < 4; k++)
System.out.print(j * k + " ");
}
```
• 1 2 3 2 4 6
• This would be true if it was j < 3.
• 1 2 3 2 4 6 3 6 9
• The variable j will range from 1 to 3 and k will range from 1 to 3.
• 1 2 2 4 3 6
• This would be true if it was k <= 3.
• 1 2 3 4 2 4 6 8 3 6 9 12
• This would be true if it was k <= 4.
• 0 1 2 3 0 2 4 6 0 3 6 9
• This would be true if k started at 0 instead of 1.

2-11-6: What value is returned as the result of `mystery(7)`?

```public int mystery(int n)
{
if (n == 0) return 1;
else return 2 * mystery (n - 1);
}
```
• 128
• This is the result of mystery(7) since this method is 2 to the nth power.
• 256
• This would be the result of mystery(8).
• 64
• This would be the result of mystery(6).
• 2
• This would be the result of mystery(1).
• 1
• This would be the result of mystery(0).
Next Section - 2.15. Exercises