Another interesting way to resolve this issue, with Python 3.8 or higher is using the concepts of Assignment Expressions, approached by PEP 572.
With these concepts we can greatly reduce the number of lines in the code. This way the code can stay:
while not (nota := input(f'Nota entre "0" e "10": ')).isdigit() or (nota := int(nota)) < 0 or nota > 10:
print('Valor INVÁLIDO!')
print(nota)
Note that the block while checking three situations:
- Checks whether the expression assigned to the variable note is not a digit;
- Checks whether the expression assigned to the variable note and converted into whole is less than 0;
- Checks whether the expression assigned to the variable note and converted into whole is greater than 10.
Case one of the three block checks while be it True we will receive the message: Valor INVÁLIDO!
and we will again be prompted a grade between "0" and "10".
Now, in case the three block checks while are False, the repeat loop will be closed, the value of the typed note will be displayed.
Anderson you are the guy, thank you very much solved instantly.
– typemark