0

I am trying to write a program where I input how many times I would like the onboard LED on a Raspberry Pi Pico H to blink, and then the LED blinking that number of times. However, when I run the attached code, I receive the following error:

  File "<stdin>", line 19, in <module>
TypeError: unsupported types for __lt__: 'int', 'str'

My code is:

import time

number = input('How many times would you like the LED to blink?')

for i in range(0, number):
    led.toggle()
    time.sleep(1)
print('Done')

Does anyone know why I am receiving these errors and how to fix them? Thanks P.S. I just got my Raspberry Pi Pico H today so not really advanced yet.

1 Answers1

0

The problem is that the default type of input() is string ('str') and you can't iterate from 0 to string, so you need to convert your input to integer value by using int(input()). The solution is:

import time

number = int(input('How many times would you like the LED to blink?'))

for i in range(0, number):
    led.toggle()
    time.sleep(1)
print('Done')
doxdeveloper
  • 109
  • 1
  • 7