# Pretest¶

The following is a pretest to test what you already know about programming in Python. Don’t worry if you don’t understand the questions yet. We don’t expect you to. Just answer the questions to the best of your ability or pick “I don’t know”.

Answers are saved on the computer you are working on by your username so we recommend logging in before starting. Login by going to the outline of a person’s head and shoulders at the top right of the window and select login. Click register if you haven’t created a username yet.

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.

1-2-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.

1-2-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.

1-2-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.

1-2-4: What is the output from the program below?

first = [10,5,10,6]
print (first[3])
second = [3,1,-2]
print (second)
second[2] = second[2] + 1
print (second[2])

• 10 [3, 1, -2] -1
• This would print 10 first if lists started at index 0, but they start at index 1.
• 6 [3, 1, -2] 2
• Remember that lists start at index 0.
• 6 [3, 1, -2] -1
• Lists start at index 0. You can modify the value at an index.
• 6 [3, 1, -2] -2
• Notice that second[2] is incremented.
• I don’t know
• That is okay. We do not expect you to know this.

1-2-5: What is the output from the program below?

first = [10,5,0]
first[1] = -5
value = first[2]
print (first)
second = [3,1,3,value]
second[3] = 100
print (second)

• [-5, 5, 0] [3, 1, 3, 5]
• The first value in first doesn't change. first[1] refers to the second item in the list.
• [10, 5, 0] [3, 1, 3, 100]
• The second item (the one at index 1) is the first list is changed to -5.
• [10, -5, 0] [3, 1, 3, 5]
• The last item in the second list is changed to 100.
• [10, -5, 0] [3, 1, 3, 100]
• The second item (the one at index 1) is the first list is changed to -5. The last item in the second list is changed to 100.
• I don’t know
• That is okay. We do not expect you to know this.

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

hello = "Good-bye"
roger = "name"
name = "Roger"
greeting = hello+" "+name
print (greeting)

• It will print "Hello Roger"
• It prints the value of hello which is "Good-bye".
• It will print "Hello name"
• It prints the value of hello which is "Good-bye".
• It will print "Good-bye Roger"
• It prints the value of hello which is "Good-bye" and the value of name which is "Roger" with a space between.
• It will print hello + " " + name
• It prints the value of the variables.
• I don’t know
• That is okay. We do not expect you to know this.

1-2-7: Given the following code segment, which of the following is true?

sum = 0 # Start out with nothing
sum = sum + number
print (sum)

• The printed result will be even and will have a decimal point.
• Adding up an even number of odd numbers results in an even sum, but there won't be a decimal point.
• The printed result will be odd and will have a decimal point.
• Adding up an even number of odd numbers results in an even sum.
• The printed result will be even and will not have a decimal point.
• Adding up an even number of odd numbers results in an even sum and there won't be a decimal point.
• The printed result will be odd and will not have a decimal point.
• Adding up an even number of odd numbers results in an even sum.
• I don’t know
• That is okay. We do not expect you to know this.

1-2-8: Given the following code segment, which of the following is true?

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

• The printed result will be even and will have a decimal point.
• Adding up an odd number of odd numbers results in an odd sum.
• The printed result will be odd and will have a decimal point.
• Adding up an odd number of odd numbers results in an odd sum. But, another answer is also true.
• The printed result will be even and will not have a decimal point.
• This would be true if any of the numbers being added had a decimal point.
• The printed result will be odd and will not have a decimal point.
• Since none of the numbers have a decimal point in them the answer will not have a decimal point. But, another answer is also true.
• I don’t know
• That is okay. We do not expect you to know this.

1-2-9: 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.

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

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

• The turtle in this example draws a pentagram.
• It loops 4 times, how can that be a pentagram?
• The turtle draws four lines of length 5, 11, 16, and 21
• It always moves forward by 100.
• The turtle draws a square.
• It draws a square with a side length of 100.
• This code will generate an error.
• No error will be generated.
• I don’t know
• That is okay. We do not expect you to know this.

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

sum = 0 # Start out with nothing