Post Exam¶

The following questions test what you have learned in this ebook. Click the “Start” button when you are ready to begin the exam. Click the “Pause” button to pause the exam (you will not be able to see the questions when the exam is paused). It will show how much time you have used, but you have unlimited time. Click on the “Finish Exam” button at the end when you are done. The number correct, number wrong, and number skipped will be displayed at the bottom of the page. Feedback for each answer will also be shown as well as your answer.

You will not be able to change your answers after you hit the “Finish Exam” button.

24-1-1: What is the output from the program below?

from turtle import *
space = Screen()
sue = Turtle()
for sides in [5,11,16,21]:
sue.forward(100)
sue.right(90)

• The turtle in this example draws a pentagram.
• This only loops 4 times, so how can it draw a pentagram?
• This code will generate an error.
• This will not cause an error.
• The turtle draws four lines of length 5, 11, 16, and 21
• This would be true if it was sue.forward(sides)
• The turtle draws a square.
• This will loop 4 times and each time draw a line of length 100 so this will be a square.

24-1-2: 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")
else:
print ("High Blood Pressure B")

• Normal
• This would be true if check_systolic returned 0 and check_diastolic returned 0.
• Hypertensive Crisis
• This would be true if check_systolic returned 3 or check_diastolic returned 3.
• High Blood Pressure B
• This would be true if check_systolic returned 2 and check_diastolic returned something other than 3.
• Prehypertension
• This would be true if check_systolic returned 1 and check_diastolic returned 1.
• High Blood Pressure A
• The function check_systolic(135) returns 1 and the function check_diastolic(100) returns 2 so this will print "High Blood Pressure A"

24-1-3: What is the output from the program below?

a = [10,5,0]
a = -5
val = a
print (a)
b = [3,1,3,val]
b = 100
print (b)

• [-5, 5, 0] [3, 1, 3, 5]
• This would be true if the first index in an array was 1 not 0.
• [10, 5, 0] [3, 1, 3, 100]
• This would be true if it was a = 5 not a = -5
• [-5, 5, 0] [3, 1, 3, 100]
• This would be true if it was a = -5.
• [10, -5, 0] [3, 1, 3, 100]
• The value of a at index 1 is changed to -5. The variable val is set to 0. Then the value of a is printed. Then b is set to [3,1,3,0]. Then the value at index 3 in b is set to 100. Then it prints the value of b.
• [10, -5, 0] [3, 1, 3, 5]
• This would be true if it was var = a before a was changed.

24-1-4: What will be the values in a, b, and c after the following lines of code execute?

a = 7;
b = 5;
c = 0;
c = a;
a = b;
b = c;

• a = 7, b = 5, c = 0
• The variable a is set to 7 initially, but it is changed to the value of b which is 5.
• a = 5, b = 7, c = 7
• While a starts at 7, b starts at 5 and c starts at 0, c is set to a copy of a's value, then a is set to a copy of b's value, and b is set to a copy of c's value.
• a = 5, b = 0, c = 7
• Since b is set to 0 and c starts out a 0 this may seem right, but c is changed to a copy of the value in a before that.
• a = 5, b = 7, c = 0
• Did you miss that c is set to a copy of the value in a?
• a = 5, b = 5, c = 7
• Did you miss that b is set to a copy of the value in c and c is set to a copy of the value in a?

24-1-5: Given the following code segment, which of the below statements is true?

hello = "Good-bye"
fred = "name"
name = "Fred"
message = hello + " " + name
print (message)

• It will print "Hello Fred"
• Even though the variable is called hello it contains "Good-bye".
• It will print "Good-bye Fred"
• Yes, this is what it will print.
• It will print "Hello name"
• It prints the value in name which has been set to "Fred".
• It will print hello + " " + name
• It will print the value of hello and then a space and the value of name.

24-1-6: Given the following code segment, which of the below statements is the most true?

sum = 0
aList = [1,3,7,19,21,131]
for number in aList:
sum = sum + number
print (sum)

• The printed result will be odd with a decimal point.
• This would true if there was an odd numer of items in aList and at least one of the numbers had a decimal point.
• The printed result will be even with a decimal point.
• This would true if at least one of the numbers had a decimal point.
• The printed result will be odd without a decimal point.
• This would true if there was an odd numer of items in aList.
• The printed result will be even without a decimal point.
• Since you are adding up an even number of odd numbers the answer will be even. Since all numbers are integers (don't have a decimal point) the answer won't have a decimal point either.

24-1-7: What is the output from the program below?

x = 4
if x == 0:
print ("Error")
else:
print (1000 / x)

• Error
• This would be true if x was initialized to 0.
• Error and 250.0 on the next line
• This would be true if the if and else statements weren't there.
• 250.0
• Since x is initialized to 4 it will print the result of 1000 divided by 4 which is 250.0.
• 1000 / 4
• This would be true if it was print ("1000 / x") instead.
• Error and 250 on the next line
• This would be true if the if and else statements weren't there and if 1000 / 4 gave an integer result.

24-1-8: Given the following code segment, which of the statements below is true?

newString = ""
phrase = "Rubber baby buggy bumpers."
for letter in phrase:
if letter in "aeiou":
newString = newString + letter
print (newString)

• The printed result will only contain vowels.
• This only adds the letter if it is a vowel.
• The printed result will only contain consonants.
• This only adds the letter if it is a vowel.
• It will print the empty string.
• No, it will add vowels to newString and print that.
• The printed result will include "y"
• The letter must be in "aeiou" to be added to newString.
• I don't know
• That is okay. We do not expect you to know this.

24-1-9: What is the output from the program below?

a = [10,5,10,6]
print (a)
b = [3,1,-2]
print b
b = b + 1
print (b)

• 6 [3, 1, -2] -2
• This would be correct if we hand't changed the value at index 2 in b.
• 6 [3, 1, -2] -1
• This will print the value at index 3 in a which is 6. Then it will print b which has [3, 1, -2]. Then it adds one to the value at index 2 in b which is -2 so -2 + 1 is -1. Then is prints the value at index 2 in b which is -1.
• 6 [3, 1, -2] 2
• This would be correct if the original value at index 2 in b was 1, but it was -2.
• 10 [3, 1, -2] 1
• This would be correct if we had added 3 to the value at index 2 in b.
• 10 [3, 1, -2] 2
• This would be correct if we had added 4 to the value at index 2 in b.

24-1-10: Given the following code segment, which of the below statements is the most true?

counter = 1
sum = 0
while counter <= 10:
sum = sum + counter
counter = counter + 2
print (sum)

• The printed result will be odd with a decimal point.
• This would be true if counter or sum had a decimal point.
• The printed result will be even with a decimal point.
• This would be true if this loop ran an even number of times and counter or sum had a decimal point.
• The printed result will be odd without a decimal point.
• Since counter starts with a value of 1 and increments by 2 each time it will always be odd. Sum starts off at 0 and adds counter each time. This will be odd when there it has added an odd number of values and even when it has added an even number of values. Since this loops till counter is greater than 10 this will loop 5 times so the result is odd.
• The printed result will be even without a decimal point.
• This would be true if the loop ran an even number of times.

24-1-11: Given the following code segment, what will be printed?

sum = 0
numList = [1,3,7,19,21,131]
for number in range(1,len(numList),2):
sum = sum + numList[number]
print(sum)

• 182