Ad
How To Gain A Valid Input From User Using Loops?
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?
Ad
Answer
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
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad