In: Computer Science
I am trying to make a robot move (theoretically), some of my code does not work in python. I am getting some errors. How can I fix it?
This is my code:
#!/usr/bin/env python.3
import time
import sys
import random
#Provide a Menu for the User
def main():
print("To control LED press 1")
print("To drive press 2")
print("To change motor speed press 3")
print("To control the Servo press 4")
while True:
option = int(input("Enter the numbers 1, 2, 3, or 4:"))
if option == 1:
LED()
elif option == 2:
Drive()
elif option == 3:
Speed()
elif option == 4:
Servo()
else:
print("Wrong letter or number, please try again.")
#Options for LED
def LED():
print("To turn led on press 5")
print("To turn led off press 6")
print("To exit press 0")
while True:
option = int(input("Enter numbers 5 or 6:"))
if option == 5:
led_on(0)
elif option == 6:
led_off(0)
elif option == 0:
main()
#Options for Drive control
def Drive():
print("To move forward press W")
print("To move right press D")
print("To turn left press A")
print("To move backwards press S")
print("To increase speed press T")
print("To decrease speed press G")
print("To stop press X")
print("To exit press Z")
while True:
option = input("Enter letters W , D, A, S, T, G, X, or Z:")
if option == "W":
fwd()
time.sleep(.3)
elif option == "D":
right()
time.sleep(.3)
elif option == "A":
left()
time.sleep(.3)
elif option == "S":
backwards()
time.sleep(.3)
elif option == "T":
increase()
time.sleep(.3)
elif option == "G":
decrease()
time.sleep(.3)
elif option == "X":
stop()
elif option == "Z":
main()
#Options for Motor speed functions
def Speed():
print("Set Speed press 7")
print("To exit press 0")
while true:
option = int(input("Enter number 7:"))
if option == 7:
Set_speed()
elif option == 0:
main()
#Options to control Servo
def Servo():
print("To move servo to the right press 8")
print("To move servo to the left press 9")
print("To move servo forward press 10")
print("To return to the menu press 0")
while True:
option = int(input("Enter numbers 8, 9, or 10:"))
if option == 8:
enable_servo()
servo(0)
time.sleep(1)
disable_servo()
elif option == 9:
enable_servo()
servo(180)
time.sleep(1)
disable_servo()
elif option == 10:
enable_servo()
servo(90)
time.sleep(1)
disable_servo()
elif option == 0:
main()
main()
/****************************main.py*****************************/
#!/usr/bin/env python.3
import time
import sys
import random
#Provide a Menu for the User
def main():
print("To control LED press 1")
print("To drive press 2")
print("To change motor speed press 3")
print("To control the Servo press 4")
while True:
option = int(input("Enter the numbers 1, 2, 3, or 4:"))
if option == 1:
LED()
elif option == 2:
Drive()
elif option == 3:
Speed()
elif option == 4:
Servo()
else:
print("Wrong letter or number, please try again.")
#Options for LED
def LED():
print("To turn led on press 5")
print("To turn led off press 6")
print("To exit press 0")
while True:
option = int(input("Enter numbers 5 or 6:"))
if option == 5:
led_on(0)
elif option == 6:
led_off(0)
elif option == 0:
main()
#Options for Drive control
def Drive():
print("To move forward press W")
print("To move right press D")
print("To turn left press A")
print("To move backwards press S")
print("To increase speed press T")
print("To decrease speed press G")
print("To stop press X")
print("To exit press Z")
while True:
option = input("Enter letters W , D, A, S, T, G, X, or Z:")
if option == "W":
fwd()
time.sleep(.3)
elif option == "D":
right()
time.sleep(.3)
elif option == "A":
left()
time.sleep(.3)
elif option == "S":
backwards()
time.sleep(.3)
elif option == "T":
increase()
time.sleep(.3)
elif option == "G":
decrease()
time.sleep(.3)
elif option == "X":
stop()
elif option == "Z":
main()
#Options for Motor speed functions
def Speed():
print("Set Speed press 7")
print("To exit press 0")
while True:
option = int(input("Enter number 7:"))
if option == 7:
Set_speed()
elif option == 0:
main()
#Options to control Servo
def Servo():
print("To move servo to the right press 8")
print("To move servo to the left press 9")
print("To move servo forward press 10")
print("To return to the menu press 0")
while True:
option = int(input("Enter numbers 8, 9, or 10:"))
if option == 8:
enable_servo()
servo(0)
time.sleep(1)
disable_servo()
elif option == 9:
enable_servo()
servo(180)
time.sleep(1)
disable_servo()
elif option == 10:
enable_servo()
servo(90)
time.sleep(1)
disable_servo()
elif option == 0:
main()
main()





I Found One syntax error with is in while true: so replace it with True
and may be indentation error...
Please let me know if you have any doubt or modify the answer , Thanks :)