Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

in python how to end the code after 10 input

incorrect = 0
max_tries = 3
choices = ['red', 'green', 'yellow']

while incorrect < max_tries:
    user_input = raw_input()
    if user_input not in choices:
        incorrect += 1
    else:
        rest_of_the_code(user_input)
        incorrect = 0

if incorrect == max_tries:
    sys.exit(1)
Comment

PREVIOUS NEXT
Code Example
Python :: Filters rows using the given condition 
Python :: assign multiple vabies in one line 
Python :: python create adictionary randomly assigning clors to categorical vairables 
Python :: Applies the f function to all Row 
Python :: python code for calculating probability of random variable 
Python :: numpy stack in new dimension 
Python :: how to sort a list randomly in python 
Python :: (908) 403-8900 
Python :: python write request must be str not bytes 
Python :: torch print floating precision 
Python :: python compactar arquivo antes de exportar 
Python :: write python command to display your name 
Python :: how to find all the installed packages in python 
Python :: how to have framer read json timestamps 
Python :: boolean for duplicate values in a column 
Python :: how to subtract numbers in python 
Python :: Deques in python3 
Python :: introduction to sets python3 
Python :: pyhdb cesu-8 
Python :: registration url 
Python :: add_node python 
Python :: features and image recongnition 
Python :: get next iterator without incrementing python 
Python :: user_info = user_info.save(commit=False) 
Python :: how do you amke function in python 
Python :: Fancier Output Formatting in python 
Python :: is elon musk a narcissist 
Python :: instal django impoer expor 
Python :: create a django and react readonly web app 
Python :: instabot source code python library 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =