Just to be clear, the statement of the reply of Maniero, already answers the question. However, there are several ways to calculate the arithmetic mean between two numbers.
If you’re using Python 3.8 or higher, you can assemble the following code:
soma = 0
for i in range(1, 3):
while (n := float(input(f'Digite sua {i}º nota: '))) < 0.0 or n > 10.0:
print('Valor INVÁLIDO!')
soma += n
media = soma / 2
print(f'{media = :.1f}')
How this code works?
Initially, we initialize the sum variable. Therefore, it will be responsible for accumulating the sum of the values captured by input().
We later implemented a loop loop for, from which the range(1, 3).
OBS: As we want to capture two values, we must implement the range(1, 3) and not range(1, 2).
Then using concepts of Assignment Expressions, addressed and duly exhausted in the PEP 572, we can implement the while block. This, will be responsible for checking whether the expression assigned to the variable n is minor that 0.0
or greater that 10.0
.
Note that while the expression assigned to the variable n is less than 0.0 or more than 10.0, we will receive the message Valor INVÁLIDO!
and we will be asked again for the value of that note.
For each valid value entered in input() your sum will be accumulated.
After we have the sum of the two inserted values, the arithmetic mean of these values will be calculated, the same being displayed by print()
From Python 3.8, added a new specifier for f-string. With this new specification we can assemble the following print():
print(f'{media = :.1f}')
The sign of equal "=" in this print() will expand the text of the expression and then the representation of the evaluated expression.