-1
I’m having trouble executing a noose while
within another while
.
I used the code below, which does everything right, but at the time I type 1 it only repeats the question "Do you want to repeat? type 1 for yes and 2 for no:", and I want you to repeat the whole program but it just repeats the last sentence.
resp = int(1)
n1 = -1
n2 = -1
while resp == 1:
while n1 > 10 or n1 < 0:
n1 = float(input("Qual valor da sua primeira nota?: "))
if n1 > 10 or n1 < 0:
print('Nota invalida.')
while n2 > 10 or n2 < 0:
n2 = float(input("Qual valor da sua segunda nota?: "))
if n2 > 10 or n2 < 0:
print('Nota invalida.')
media = (n1 + n2) / 2
print('A sua média foi de {}'.format(media))
resp = int(input('Deseja repetir? digite 1 para sim e 2 para não: '))
This happens because the
n1
andn2
continue with the entered value, reset the two variables after the question "Want to repeat?"– Paulo Marques