LC101 Class 1.10 Name: ____________________
Review Questions (Ch. 10-11)
1. What is the printout of the following code?
- universe_a = [1, 2, 3, 4, 5]
- universe_b = universe_a
-
- def parallel_universe(b):
- b[2] = 42
-
- parallel_universe(universe_a)
- print(universe_b[2])
- print(universe_a[2])
2. Identify the compiler error. What might the user have intended to print?
- def failing_to_scramble(ingredients):
- for x in range(len(ingredients)):
- temp = x
- ingredients[x] = ingredients[x+1]
- ingredients[x+1] = temp
-
- ingredients = ('e', 'g', 'g', 's')
- print(failing_to_scramble(ingredients))
3. What is the printout of the following function?
- def shuffle_n_cheat(deck):
- new_deck = []
- for card in deck:
- new_deck.append(card)
- new_deck[len(deck) - 1] = new_deck[0]
- return new_deck
- deck = ["A♠", "4♥", "8♣", "J♦"]
- print(shuffle_n_cheat(deck))
4. What is the printout of the following code?
- def control(the_matrix):
- for i in range(len(the_matrix)):
- for j in range(len(the_matrix[i])):
- if i == j:
- the_matrix[i][j] = 0
-
- the_matrix = [[1,0,0],
- [0,1,0],
- [0,0,1]]
- control(the_matrix)
- print(the_matrix)