НАЙДИТЕ ОШИБКУ И ИСПРАВЬТЕ ЕЕ И НАПИШИТЕ КАК ПРАВИЛЬНО КОДОМ
from turtle import *
from random import randint
shape("turtle")
colors = ["blue","red","orange","purple"]
shredder = randint(1,10)
user_choose = 0
count_commands = 0 # добавленный счетчик команд на перемещение
while user_choose != shredder:
user_choose = str.lower(input("Select direction Left/Right/Direct/Back"))
if user_choose == str.lower("left"):
left(90)
for color_turtle in colors:
pensize(randint(1,10))
color(color_turtle)
forward(randint(5,30))
user_choose=randint(1,10)
if user_choose != shredder:
count_commands += 1 # увеличиваем счетчик команд на перемещение
print("Shreder is not...")
elif user_choose == str.lower("right"):
right(90)
for color_turtle in colors:
pensize(randint(1,10))
color(color_turtle)
forward(randint(5,30))
user_choose=randint(1,10)
if user_choose != shredder:
count_commands += 1 # увеличиваем счетчик команд на перемещение
print("Shreder is not...")
elif user_choose == str.lower("direct"):
for color_turtle in colors:
pensize(randint(1,10))
color(color_turtle)
forward(randint(5,30))
user_choose=randint(1,10)
if user_choose != shredder:
count_commands += 1 # увеличиваем счетчик команд на перемещение
print("Shreder is not...")
elif user_choose == str.lower("back"):
left(180)
for color_turtle in colors:
pensize(randint(1,10))
color(color_turtle)
forward(randint(5,30))
user_choose=randint(1,10)
if user_choose != shredder:
count_commands += 1 # увеличиваем счетчик команд на перемещение
print("Shreder is not...")
if count_commands == 15: # проверяем, достиг ли счетчик 15 команд на перемещение
print("You lost! Shredder was not found in 15 commands.")
exitonclick()
print("Shredder here!")
exitonclick()
Ответы
from turtle import *
from random import randint
shape("turtle")
colors = ["blue", "red", "orange", "purple"]
shredder = randint(1, 10)
user_choose = 0
count_commands = 0 # added command counter
while user_choose != shredder:
user_choose = str.lower(input("Select direction Left/Right/Direct/Back: "))
if user_choose == "left":
left(90)
elif user_choose == "right":
right(90)
elif user_choose == "direct":
pass
elif user_choose == "back":
left(180)
else:
print("Invalid direction. Please choose Left, Right, Direct, or Back.")
continue
for color_turtle in colors:
pensize(randint(1, 10))
color(color_turtle)
forward(randint(5, 30))
user_choose = randint(1, 10)
if user_choose != shredder:
count_commands += 1
print("Shredder is not here...")
if count_commands == 15:
print("You lost! Shredder was not found in 15 commands.")
exitonclick()
print("Shredder is here!")
exitonclick()