So, I need to make a code where turtle move when you press w,a,s,d, without importing keyboard in python.
from turtle import *
x=100
z=90
v=input()
while True:
if v == 'w':
forward(x)
if v == 's':
backward(x)
if v == 'd':
right(z)
if v == 'a':
left(z)
there is the code.
The problem is, when i press any of these buttons turtle moves infinitely, without stopping. I have no idea how to fix this, and im kinda sure its easy to fix. It has to be infinite, so "while" is required. Also dont mind my grammar,I think I did some grammar mistakes here. Code shouldn't be fully rewritten.
To fix the issue of the turtle moving infinitely without stopping, you need to continuously update the value of
vinside the while loop to capture the user input repeatedly.Here's the modified code: