I am writing a program that needs input in the console to control where a turtle goes on the screen. For example, if the user of the program types w
in the console, and presses enter, the turtle should move forward 30 units. If the user types a
, the turtle should turn left 45 degrees, etc.
I wrote some functions and used an infinite while
loop for the program. It looks like this:
def movemattfd():
matt.fd(30)
def movemattlt():
matt.lt(45)
def movemattrt():
matt.rt(45)
def movemattbk():
matt.back(30)
def movematt():
while True:
input()
if input() == 'w':
movemattfd()
if input() == 'a':
movemattlt()
if input() == 'd':
movemattrt()
if input() == 's':
movemattbk()
def main():
windowHeight = 500
windowWidth = 500
turtle.screensize(windowWidth, windowHeight, None)
movematt()
main()
The program works, except when I enter w
in the console, it takes at least 2 entries to get my turtle to move forward. It takes even more when I try to turn my turtle right.
Any ideas? Thanks in advance.
elif
keywordinput()
right afterwhile True:
line?