Code Writer
Level 3, 2024-11-25
Answers should be legal Python code, including indentation. Use the underscore _ to show a space.
Special functions: print(), range(), sqrt(), str()
Assume you have 2 lists of numbers with 12 elements each: B and Z. Add the 5th elements of the lists together.
Use: variables[1]
|
|
Test Using: B = [1,2,3,...,12], Z = [1,2,3,...,12] |
Create two strings and join them together with a space between
Use: variables[1]
|
|
|
Assume you have a list of names, B. Write code to count the number of times the name "Mike" appears in the list.
Use: variables, loops, if[2]
|
|
Test Using: B = [] B = ['Mike'] B = ['Mike','Octavian','Edward','Mike'] |
A list contains a series of attacks on an enemy. The list looks like [1,2,3,1,1,2,...] where each element in the list is a number that means a type of attack:
1 is a light attack, taking 1HP 2 is a medium attack taking 4HP 3 is a strong attack taking 17HP
Write code to calculate the total amount of HP damage caused by all the attacks.
Use: variables, loops, if[3]
|
|
Test Using: attacks = [1,2,3] attacks = [1,2,3,3,2,1] attacks = [47,46,94] |
A list contains numbers that are the amount of HP damage caused by a series of attacks. Your character starts with 174HP. 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] |
Use a loop to print the average of the numbers from 4 to 19
Use: variables, loops[2]
|
|
|
A list contains a series of attacks on an enemy. The list looks like [1,2,3,1,1,2,...] where each element in the list is a number that means a type of attack:
1 is a light attack, taking 3HP 2 is a medium attack taking 6HP 3 is a strong attack taking 17HP
Write code to calculate the total amount of HP damage caused by all the attacks.
Use: variables, loops, if[3]
|
|
Test Using: attacks = [1,2,3] attacks = [1,2,3,3,2,1] attacks = [47,46,94] |
|