Code Writer
Level 3, 2026-09-27
Answers should be legal Python code, including indentation. Use the underscore _ to show a space.
Special functions: print(), range(), sqrt(), str()
Assume you have a list of numbers X. Print the 9th element of X.
Use: variables[1]
|
|
|
Test Using: X = [1,2,3,4,5,6,7,8,9,10] |
Use a loop to print the sum of the numbers from 1 to 18
Use: variables, loops[2]
|
|
|
|
Assume you have a list of letters Z. Write code to count the number of times the letter "F" appears in the list.
Use: variables, loops, if[2]
|
|
|
Test Using: Z = [] Z = ['F','a','z'] Z = ['F','F','F'] |
Assume you have a list of numbers VAR. Write code to add up the numbers in the list that are smaller than 8
Use: variables, loops, if[3]
|
|
|
Test Using: VAR = [] VAR = [5,6,7,8,9,10,11,12,13,14,15] VAR = [86,5,30] |
A factorial of a number is all the numbers from 1 to that number multiplied together, so 4! = 1x2x3x4. Write code using a loop to calculate 90!
Use: variables, loops, str()[2]
|
|
|
|
Assume you have a list of letters Q. Write code to count the number of times the letter "B" appears in the list.
Use: variables, loops, if[2]
|
|
|
Test Using: Q = [] Q = ['B','a','z'] Q = ['B','B','B'] |
Assume you have two non-empty lists of numbers X and Y. Create a new variable that is equal to the first element of each list added together.
Use: variables[1]
|
|
|
Test Using: X = [1], Y = [1] X = [1,2,3], Y = [3,2,1] X = [82,22,53], Y = [94,95,64] |
Assume you have a list of numbers B. Print the 5th element of B.
Use: variables[1]
|
|
|
Test Using: B = [1,2,3,4,5,6,7,8,9,10] |
Assume you have a list VAR with at least 2 elements. Create a new variable that is equal to the first two elements added together.
Use: variables[1]
|
|
|
Test Using: VAR = ['a','b','c'] VAR = ['big','dog'] VAR = [63,65,37] |
|