Great! In the previous examples, we showed nested
for loops. Naturally,
while loops can be nested too!
final_score = 0
counter = 0
while counter < 10:
current_number = input('Please provide a number to add: ')
while not current_number.isnumeric():
current_number = input('That\'s not a number! Try again: ')
final_score += int(current_number)
counter += 1
print('The score is', final_score)
The program above adds 10 numbers entered by the user. We use nested
while loops. The outer loop is responsible for reading in 10 numbers.
The inner loop, in turn, makes sure that the user enters a number, and not letters or special characters. It keeps asking for input until it's numerical. When we get a legit number at last, we add it to the
final_score in the outer loop.