Jake Armstrong Jake Armstrong - 4 months ago 23
Python Question

Raspberry Pi 2 Model B is preventing my def function

I have a raspberry Pi 2 Model B. I am trying to make a program that turns on an LED when the input is 'Yes'. What happens is that I get a syntax error saying that def was the error with the arrow pointing at the f. Here is my code:

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)

GPIO.setwarnings(False)

GPIO.setup(40, GPIO.OUT)

GPIO.setup(38, GPIO.OUT)

GPIO.output(38, 1)

def start():
main(input("> ")

def main(yn):
while True:
if yn == 'Yes':
GPIO.output(40, 1)
print("The LED is on!")
break
if yn == 'No':
GPIO.output(40, 0)
print("The LED is off!")
break
start()
start()


Please help and thank you in advance!

Answer

Your start function is missing a closing parenthesis:

def start():
    main(input("> "))