Code Writer
Level 3, 2026-05-28
Answers should be legal Python code, including indentation. Use the underscore _ to show a space.
Special functions: print(), range(), sqrt(), str()
A list contains numbers that are the amount of HP damage caused by a series of attacks. Your character starts with 145HP. Write code that works out how much damage you have taken and prints "Dead" if you are killed.
Use: variables, loops, if[3]
|
|
|
Test Using: attacks = [1] attacks = [50,50,50] attacks = [1,1,1] |
Assume you have a list Q with at least 2 elements. Create a new variable that is equal to the first two elements added together.
Use: variables[1]
|
|
|
Test Using: Q = ['a','b','c'] Q = ['big','dog'] Q = [20,47,51] |
A rectangle has sides of 9 and 4. Create variables for the sides of the shape and then calculate its perimeter
Use: variables[2]
|
|
|
|
Assume you have a list variable LIST of numbers. Use a variable to add the items in the list
Use: variables, loops[2]
|
|
|
Test Using: LIST = [1] LIST = [1,2,3,4,5,6,7,8,9] LIST = [5,88,81] |
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 20!
Use: variables, loops, str()[2]
|
|
|
|
Assume you have a variable X. If X is smaller than 6 add 8 to it, otherwise subtract 7 from it
Use: variables, if[2]
|
|
|
Test Using: X = 0 X = 6 X = 10 |
Assume you have a list of names, A. Write code to count the number of times the name "Flip" appears in the list.
Use: variables, loops, if[2]
|
|
|
Test Using: A = [] A = ['Flip'] A = ['Flip','Mike','Jenny','Flip'] |
Set two variables to different strings then make a new variable that combines them with a "f" in between
Use: variables[1]
|
|
|
|
|