Skip to content

Practice Quiz 1 (Ch 1–2)

Name: ___________________________________

This work complies with the JMU Honor Code. I have neither given nor received unauthorized assistance. I will not discuss the quiz contents with anyone who has not taken the quiz.
Initials: ____________

Written Portion

Question 1  (2.5 pts)

Identify each of the numbered items in the image.

Variable: 3

Expression: 5

Statement: 4

Comment: 1

String Literal: 2

Question 2  (3 pts)

Assuming that the following assignments have occurred, determine the type of the result of each of expression in the table, or determine if the expression would result in an error.

a = 7
b = "7"
c = 7.0
Expression Type (int, float, str, or Error)
a + b Error
a * 2 int
a / 2 float
a % 2 int
a + c float
"00" + b str

Question 3  (1.5 pts)

What will be printed when the following code snippet executes?

first = "XYZ"
second = "ABC"
result = first + second
print(result[1] + result[4])

Answer: YB

Question 4  (3 pts)

The following code snippets are designed to help estimate the number of eggs produced by a group of chickens, assuming that each chicken produces four eggs per day. Each snippet has either a Syntax error (S), a Run-time error (R), or a Logic error (L). Identify the category of error each snippet has.


count = int(input("Enter the number of chickens: "))
print(f"You should expect {count + 4} eggs per day!")
Answer: L


count = int(input("Enter the number of chickens:
print(f"You should expect {count * 4} eggs per day!")
Answer: S


count = int(input("Enter the number of chickens: "))
amount = "count" * "4"
print(f"You should expect {amount} eggs per day!")
Answer: R

Coding Portion

Question 5  (5 pts)

Complete a program named names.py that prints a provided name formatted as "Last, First". Your program must begin with the following lines:

first = "James"
last = "Madison"

Add a single print statement that uses the above variables to output the following string:

Madison, James

Gradescope will change the values of first and last before running your program. Your output must correspond to the values chosen by Gradescope.

Question 6  (10 pts)

The Harrisonburg 500 is an annual bicycle race that takes place at the famous Harrisonburg Speedway. The Speedway track is five miles in length. The full race involves completing 100 laps.

Write a program named race.py to be used by the support crews for the race. Your program must prompt the user for the total distance, in miles, completed by a participant. This value will be provided as an integer. The program will then report how many total laps the participant has completed, the number of miles they have completed in their current lap, and the percentage of the race they have finished.

The following example illustrates the expected format:

Distance: 11
You have completed 2 full laps and 1 mile(s) of lap 3.
The race is 2.2% complete.

The prompts and output should match this example exactly, substituting the appropriate values based on the input. The percentage must be rounded to one decimal place.