12 Review¶
test_01.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # Write a function called "f" that will pass all the tests below:
# --- Tests. Do not change anything below this line. ---
# Write your code above the line to pass all the tests.
if f(30, 40) == 70:
print("Test 1 passed")
else:
print("Test 1 failed")
if f(0, 0) == 0:
print("Test 2 passed")
else:
print("Test 2 failed")
if f(-20, 10) == -10:
print("Test 3 passed")
else:
print("Test 3 failed")
if f(0.5, 0.5) == 1:
print("Test 4 passed")
else:
print("Test 4 failed")
|
test_02.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # Write a function called "f" that will pass all the tests below:
# --- Tests. Do not change anything below this line. ---
# Write your code above the line to pass all the tests.
if f(0, 0) == 0:
print("Test 1 passed")
else:
print("Test 1 failed")
if f(5, 0) == 0:
print("Test 2 passed")
else:
print("Test 2 failed")
if f(10, 10) == 100:
print("Test 3 passed")
else:
print("Test 3 failed")
if f(0.5, 0.5) == 0.25:
print("Test 4 passed")
else:
print("Test 4 failed")
|
test_03.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # Write a function called "f" that will pass all the tests below:
# --- Tests. Do not change anything below this line. ---
# Write your code above the line to pass all the tests.
if f(10, 10, 1) == 20:
print("Test 1 passed")
else:
print("Test 1 failed")
if f(15, 10, 1) == 25:
print("Test 2 passed")
else:
print("Test 2 failed")
if f(10, 10, 2) == 10:
print("Test 3 passed")
else:
print("Test 3 failed")
if f(10, 10, 10) == 2:
print("Test 4 passed")
else:
print("Test 4 failed")
if f(4, 6, 2) == 5:
print("Test 5 passed")
else:
print("Test 5 failed")
if f(150, 50, 50) == 4:
print("Test 6 passed")
else:
print("Test 6 failed")
|
test_04.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # Write a function called how_is_the_temperature that returns a string based
# on the temperature passed into it.
# Try to get this to work based on temperature ranges, rather than exact
# temperatures.
# --- Tests. Do not change anything below this line. ---
# Write your code above the line to pass all the tests.
if how_is_the_temperature(95) == "Hot":
print("Test 1 passed")
else:
print("Test 1 failed")
if how_is_the_temperature(85) == "Warm":
print("Test 2 passed")
else:
print("Test 2 failed")
if how_is_the_temperature(70) == "Great":
print("Test 3 passed")
else:
print("Test 3 failed")
if how_is_the_temperature(50) == "Cool":
print("Test 4 passed")
else:
print("Test 4 failed")
if how_is_the_temperature(30) == "Cold":
print("Test 5 passed")
else:
print("Test 5 failed")
|
test_05.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # Write a function that figures out if a number is even or odd.
# Make it work for every number, not just the ones we test here.
# --- Tests. Do not change anything below this line. ---
# Write your code above the line to pass all the tests.
if even_or_odd(0) == "Even":
print("Test 1 passed")
else:
print("Test 1 failed")
if even_or_odd(1) == "Odd":
print("Test 2 passed")
else:
print("Test 2 failed")
if even_or_odd(-1) == "Odd":
print("Test 3 passed")
else:
print("Test 3 failed")
if even_or_odd(100) == "Even":
print("Test 4 passed")
else:
print("Test 4 failed")
if even_or_odd(1001) == "Odd":
print("Test 5 passed")
else:
print("Test 5 failed")
|
test_06.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # Create a class called bird, with the attributes x and change_x, and a method
# called "move". Have it pass the tests below.
# --- Tests. Do not change anything below this line. ---
# Write your code above the line to pass all the tests.
my_bird = Bird()
if my_bird.x == 0:
print("Test 1 passed")
else:
print("Test 1 failed")
if my_bird.change_x == 0:
print("Test 2 passed")
else:
print("Test 2 failed")
my_bird.change_x = 5
my_bird.move()
my_bird.move()
if my_bird.x == 10:
print("Test 3 passed")
else:
print("Test 3 failed")
|