Given this function:
What will the function return given the arguments 5 for a and 5 for b?
( ) 7
( ) 10
( ) 20
( ) 14
10
Unlike Pyret, where you used if-expressions, in Python you can create if-statements. The difference is that in Pyret, an if-expression needed to evaluate to a single value, whereas in Python, an if-statement just checks if a given condition is true or false and runs the appropriate code.
Fill in the blanks for this Python function such that it returns the string "hello Professor Kathi".
Blank1: def
Blank2: hello
Blank3: return
Blank4: b
Blank5: "Kathi"
In Pyret, every function evaluates to a certain value. In Python, if you want a function to return a piece of data you need to explicitly write return.
Given this code:
What is the value of the variable a?
( ) Python throws an error– data is immutable and cannot be changed.
( ) Python throws an error– the name b cannot be the value of a.
( ) 5
( ) 9
9
Python makes use of variables– names of data that can be reassigned and mutated.
Given this list of letters,
Fill in the blank to add the string 'd' to letters:
append
The list method append adds a piece of data to the end of a list.
Given this list of letters:
Which of the following lines of code correctly gets 'b' from the list?
( ) letters['b']
( ) letters[2]
( ) letters.get('b')
( ) letters[1]
letters[1]
To access the data from a list at index i, write list[i]