#separator:tab #html:true #tags:python-first-programs-quiz #columns:Front Back "
What does print(""3"" + ""4"") print?
73434Both 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?
intfloatstrstrinput 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?
3.4 and 03 and 23 and 0.42 and 33 and 217 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)
total_price2nd_placemy-nameseconds_per_dayclasstotal_priceseconds_per_dayNames 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""]?
redgreenbluegreenThe 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])3 8 34 8 14 5 14 8 34 8 1append 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)8""8""NoneNonedouble 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?
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.