Question:
Anyone know the difference between choice 1 and choice 2? Why do i need store the test all function in the count variable in order to update the count variable?
(The purpose of the count variable is just to alternate the messages said if the assertion test fails). I also tried choice 3 but i don’t know why that doesn’t work
Repl link:
import turtle
Tu = turtle.Turtle()
Tu.shape("turtle")
screen = turtle.Screen()
screen.setup(1000, 1000)
Tu.speed(10)
Tu.penup()
count = 2
def word_to_number(the_input):
input_dict = {
"usain": "1st place",
"me": "2nd place",
"qazi": "3rd place",
"1st place": "Usain",
"2nd place": "Me",
"3rd place": "Qazi",
}
try:
return input_dict[the_input]
except KeyError:
return "Please enter a name or what place you came in"
raise RuntimeError(f"something is wrong with the value:{the_input}")
def test_all(incorrect_count):
Tu.goto(0, 0)
Tu.clear()
try:
assert word_to_number("1st place") == "Usain"
assert word_to_number("me") == "2nd place"
assert word_to_number("qazi") == "3rd place"
assert word_to_number("usain") == "1st place"
assert word_to_number("3rd place") == "Qazi"
assert word_to_number("2nd ple") == "Me"
Tu.color("green")
Tu.begin_fill()
Tu.circle(50)
Tu.end_fill()
Tu.goto(-100, -50)
Tu.write("Correct!Good job!", font=("Ariel", 20, "normal"))
Tu.goto(0, -60)
except AssertionError:
Tu.color("red")
Tu.begin_fill()
Tu.circle(50)
Tu.end_fill()
Tu.goto(-70, -50)
Tu.write("Incorrect!", font=("Ariel", 20, "normal"))
Tu.goto(-300, -75)
Tu.write(
"Something is wrong with the assertion inputs", font=("Ariel", 20, "normal")
)
Tu.goto(-70, -100)
if incorrect_count % 2 == 0:
Tu.write("keep Trying!", font=("Ariel", 20, "normal"))
else:
Tu.write("Do Not Give up!", font=("Ariel", 20, "normal"))
Tu.goto(0, -110)
incorrect_count += 1
return incorrect_count
# choice 1
while True:
print("Enter a name or what place you came in")
print("Choices: Usain, Me, Qazi for names and 1st, 2nd, 3rd for places")
my_input = input(">").lower().strip()
output = word_to_number(my_input)
print(output)
count = test_all(count)
# choice 2
while True:
print("Enter a name or what place you came in")
print("Choices: Usain, Me, Qazi for names and 1st, 2nd, 3rd for places")
my_input = input(">").lower().strip()
output = word_to_number(my_input)
print(output)
test_all(count)
# choice 3
def test_all():
incorrect_count = 2
Tu.goto(0, 0)
Tu.clear()
try:
assert word_to_number("1st place") == "Usain"
assert word_to_number("me") == "2nd place"
assert word_to_number("qazi") == "3rd place"
assert word_to_number("usain") == "1st place"
assert word_to_number("3rd place") == "Qazi"
assert word_to_number("2nd ple") == "Me"
Tu.color("green")
Tu.begin_fill()
Tu.circle(50)
Tu.end_fill()
Tu.goto(-100, -50)
Tu.write("Correct!Good job!", font=("Ariel", 20, "normal"))
Tu.goto(0, -60)
except AssertionError:
Tu.color("red")
Tu.begin_fill()
Tu.circle(50)
Tu.end_fill()
Tu.goto(-70, -50)
Tu.write("Incorrect!", font=("Ariel", 20, "normal"))
Tu.goto(-300, -75)
Tu.write(
"Something is wrong with the assertion inputs", font=("Ariel", 20, "normal")
)
Tu.goto(-70, -100)
if incorrect_count % 2 == 0:
Tu.write("keep Trying!", font=("Ariel", 20, "normal"))
else:
Tu.write("Do Not Give up!", font=("Ariel", 20, "normal"))
Tu.goto(0, -110)
incorrect_count += 1
return incorrect_count
input()