Learn Without Walls
← Back to Module 3

Module 3 Quiz: Input, Output & String Formatting

12 questions • Select the best answer for each question

Question 1

What is the output of print("a", "b", "c", sep="-")?

  • a b c
  • abc
  • a-b-c
  • a - b - c
Correct: c) The sep parameter replaces the default space separator with "-".

Question 2

What data type does input() always return?

  • int
  • str
  • The type of whatever the user enters
  • float
Correct: b) input() always returns a string, even if the user types a number. You must convert it with int() or float() if you need a number.

Question 3

Which code correctly gets an integer from the user?

  • age = input("Age: ")
  • age = int("Age: ")
  • age = input(int("Age: "))
  • age = int(input("Age: "))
Correct: d) input() gets the string from the user, then int() wrapping it converts that string to an integer.

Question 4

What does the end parameter in print() control?

  • What character is printed at the end (default is newline)
  • What character separates the values
  • How many times to print
  • The last value to print
Correct: a) By default, print() adds \n (newline) at the end. The end parameter lets you change this to a space, empty string, or anything else.

Question 5

What does f"{3.14159:.2f}" produce?

  • 3.1
  • 3.141
  • 3.14
  • 3.14159
Correct: c) The :.2f format specifier rounds to 2 decimal places, producing 3.14.

Question 6

What is the output of this code?

name = "Alice"
print(f"Hello, {name}!")
  • Hello, {name}!
  • Hello, Alice!
  • Hello, "Alice"!
  • Error
Correct: b) The f prefix makes it an f-string, so {name} is replaced with the value of the variable name.

Question 7

What does f"{0.75:.1%}" produce?

  • 0.75%
  • 75%
  • 0.8%
  • 75.0%
Correct: d) The % format specifier multiplies by 100 and adds a percent sign. .1 gives 1 decimal place, producing 75.0%.

Question 8

What is the output of print("Hi", end="") ; print("there")?

  • Hithere
  • Hi there
  • Hi and there on separate lines
  • Error
Correct: a) end="" removes the newline after "Hi", so the next print continues on the same line with no space, producing Hithere.

Question 9

What does f"{1000000:,}" produce?

  • 1000000
  • 1.000.000
  • 1,000,000
  • ,1000000
Correct: c) The :, format specifier adds comma separators for thousands.

Question 10

What happens when you run: num = input("Number: ") and the user types 42?

  • num is the integer 42
  • num is the string "42"
  • num is the float 42.0
  • Python auto-detects it as an integer
Correct: b) input() always returns a string, regardless of what the user types. The value is "42" (a string), not the number 42.

Question 11

What is the difference between "Hello, " + name and print("Hello,", name)?

  • There is no difference
  • Concatenation adds a space; commas do not
  • Commas can only be used with strings
  • Concatenation does not add a space; commas do
Correct: d) Concatenation with + joins strings exactly as-is (no automatic space). print() with commas automatically adds a space between values.

Question 12

Which approach is generally recommended for formatting strings in modern Python?

  • String concatenation with +
  • The .format() method
  • f-strings (f"...")
  • The % operator
Correct: c) f-strings (introduced in Python 3.6) are the modern, preferred approach. They are more readable and more concise than other methods.

Quiz Results