Skip to content

Quiz Review

Part 1 will be closed book. For parts 2 and 3, you will be allowed to refer to the course website and your previous assignments.

Part 1

Make sure you know these terms well enough that you can match them to their definitions:

  • Comment - Descriptive text that is ignored when the program is run.
  • String - A sequence of letters, numbers and symbols inside a set of quotes.
  • Arithmetic Expression - A mathematical expression that evaluates to a number.
  • Boolean Expression - A mathematical expression that evaluates to either True or False.
  • Modulo (mod) - Calculates what the remainder would be when two numbers are divided.
  • Variable - A symbol that represents a stored value in the computer.
  • Function - A small task carried out by Python.
  • Function Call - The code to trigger a function, consisting of its name and a list of arguments.
  • Argument - A piece of information sent to a function.
  • Module - An add-on to Python, providing access to extra functions and features.

Part 2

Write a program that asks the user for two numbers (each in a separate input statement).

The program should output a sentence that includes:

  • The two numbers
  • The sum of the two numbers (ie, what they add to)
  • Whether the sum is even or odd.

For example, you program might look like this when it's run:

Enter a number: 5
Enter another number: 3
The numbers 5 and 3 add to the even number 8
or
Enter a number: 7
Enter another number: 4
The numbers 7 and 4 add to the odd number 11

Part 3

Rewrite the following line of code using an f-String:

make = "Honda"
model = "Civic"
year = 2018

print("The car is a", make, model, "built in", year)


Answers

# Part 2

num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))

sum = num1 + num2

if sum % 2 == 0:
    print(f"The numbers {num1} and {num2} add to even number {sum}")
else:
    print(f"The numbers {num1} and {num2} add to odd number {sum}")

# Part 3

make = "Honda"
model = "Civic"
year = 2018

print("The car is a", make, model, "built in", year)

print(f"The car is a {make} {model} build in {year}")