#separator:tab #html:true #tags:python-first-programs-quiz #columns:Front Back "

What does print(""3"" + ""4"") print?

  1. 7
  2. 34
  3. An error message, because text cannot be added
"

Both values are in quotation marks and are therefore text. With text, + joins the two together; nothing is calculated.

"

Someone types the number 19 at age = input(""Age? ""). What type does age have?

  1. int
  2. float
  3. str
"

input always returns a string, even if only digits were typed. To calculate with it, you convert it with int(...).

What do 17 // 5 and 17 % 5 return?

  1. 3.4 and 0
  2. 3 and 2
  3. 3 and 0.4
  4. 2 and 3

17 divided by 5 is 3 with remainder 2. // returns the whole-number part, % the remainder.

Which of these can be the name of a variable in Python? (several are right)

  1. total_price
  2. 2nd_place
  3. my-name
  4. seconds_per_day
  5. class

Names consist of letters, digits and underscores and do not start with a digit. A hyphen would be a minus sign, and class is a reserved word in Python.

"

What does print(colors[1]) print if colors = [""red"", ""green"", ""blue""]?

  1. red
  2. green
  3. blue
" "

The index starts at 0: colors[0] is ""red"", colors[1] is ""green"". You reach the last element with colors[-1].

"

What does this program print?

numbers = [3, 8, 1]
numbers.append(5)
print(len(numbers), max(numbers), sorted(numbers)[0])
  1. 3 8 3
  2. 4 8 1
  3. 4 5 1
  4. 4 8 3

append adds the 5 at the end, so the list then has four elements. The largest is still the 8, and sorted(numbers)[0] is the smallest element, the 1. The list numbers itself stays unsorted.

"

What value does result have at the end?

def double(number):
print(number * 2)


result = double(4)
  1. 8
  2. ""8""
  3. None
"

double only prints the 8 but returns nothing, because a return is missing. A function without return returns None.

A program stops with NameError: name 'totl' is not defined. What most likely happened?

  1. Python is too old for this program.
  2. A name is misspelt, or the variable has no value yet at this point.
  3. A number was divided by zero.

A NameError means that Python does not know a name. Usually it is a typo like here, where total was probably meant, or the variable only gets a value further down.