Exam Questions for Chapters 3 and 4¶
The following questions test what you have learned in chapters 3 and 4. 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.
- This would be true if it was print ("name" + "words"), but name and words are not in quotes so the value of each will be printed.
- name + words
- This would be true if it was print ("name + words").
- John Smith + likes to play outside.
- The would be true if it was print (name + " +" + words).
- John Smith likes to play outside.
- When you use a variable name in a print statement the value of the variable is printed. The + sign is used to join strings together.
- Tests to see if the values on each side of the expression are equal
- This would be true if it was cat == "meow"
- Assigns the name on the left to the value on the right
- A name on the left and a value on the right creates a variable with that name and that value.
- Copies the value from the right to the left
- This would be true if it was a variable name on the right instead of a string.
- Creates two new objects, one named cat and one named meow
- This creates a variable and sets its value. It doesn't create an object.
- I only
- There are no quotes around the string so this gives an error.
- II only
- When you use '+' it appends the strings together so this will print the correct string
- III only
- Answer III will not work since there is no variable called Morrissey.
- all of them
- Answer II will work, but not answer I or answer III. Number I has no quotes around the string. In III there is no variable called Morrissey.
- This would be true if it was 4 % 2 since 2 goes in evenly into 4.
- This would be true if you were trying to divide 5 by a number that was larger than 5.
- This would be true if it was 5 % 3.
- 2 goes into 5 2 times with a remainder of 1.
- While var2 starts out set to 3 it changes when it is set to a copy of the value in var1.
- While var2 starts out set to 3 it changes to a copy of the value in var1 which is 10.
- This is the value of var1 after the code executes.
- You would have to set var2 to 0 at some point for this to be true.
- THIS IS A TEST
- Strings are immutable. Any change to a string returns a new string.
- this is a test
- This would be true if the question asked for the value of better.
- This is a test
- This would be true if the question asked for the value of betterStill
- This is a test, really!
- This would be true if the question asked for the value of more.
4-7-1: What is printed after the following code is run?
name = "John Smith" words = " likes to play outside." print (name + words)
4-7-2: In the following code, what does the “=” do?
cat = "meow"
4-7-3: Which of the following line(s) of code will print out “My name is Morrissey”?
I. print (My name is Morrissey) II. var1 = "My name is " var2 = "Morrissey" var3 = var1 + var2 print (var3) III. M = "M" orrissey = "orrissey" print ("My name is " + Morrissey)
4-7-4: What is printed after the following executes?
result = 5 % 2 print(result)
4-7-5: What is the value of var2 after the following code executes?
var2 = 3 var1 = 10 var2 = var1 var3 = var2 var1 = 18
4-7-6: What is the value of sentence after the following code executes?
sentence = "THIS IS A TEST" better = sentence.lower() betterStill = better.capitalize() + "." more = sentence + ", really!"