Answer the question
In order to leave comments, you need to log in
How to implement a limited number of except attempts?
Suppose there is a code where the site is accessed via requests.get
Is it possible to somehow implement such logic, in which try except will be executed 10 times, and when the attempts are over, call system.exit (1)?
Answer the question
In order to leave comments, you need to log in
Enter a new variable that will iterate the number of attempts:
counter = 0 # Счётчик
while counter <= 10:
input_number = int(input('Enter the number: ')) #requests.get()
try:
result = 1/input_number
counter += 1
except:
print('Wrong number, try again!')
counter += 1
else:
print('End!') #system.exit(1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question