-1
from sense_emu import SenseHat
sense = SenseHat()

text_red_prompt = input('How red do you want the text to be: _____ [Key Value between 0 - 255]'
text_red = int(text_red_prompt)

text_green_prompt = input('How green do you want the text to be: _____ [Key Value between 0 - 255]'
text_green = int(text_green_prompt)

How do I code using loops such that when a User were to input a number that is more than 255, the system will prompt the user to enter again before the system moves on to the text_green_prompt?

rdas
  • 20,604
  • 6
  • 33
  • 46
matplob
  • 3
  • 1

1 Answers1

1

you could try a loop like below for each of you vars

validInput = False
while not validInput:
    text_red_prompt = input('How red do you want the text to be: _____ [Key Value between 0 - 255]')
    text_red = int(text_red_prompt)
    if text_red >= 0 and text_red <= 255:
        validInput = True
Harvey
  • 114
  • 1
  • 8
  • Thank you Harvey, if you dont mind can you explain to me Line 2 'while not validInput'? – matplob Oct 04 '19 at 09:11
  • 1
    `while not validInput` essentially is `while validInput != True`, which means loop while the variable validInput is equal to False this essentially creates a loop which will last forever, unless validInput is set to True – Harvey Oct 04 '19 at 09:12
  • That solved my doubts and clarification. Thanks! – matplob Oct 04 '19 at 09:21
  • No Problem. If it's working you should mark the answer by clicking the tick below the vote button. – Harvey Oct 04 '19 at 10:05