-4
Guys, how do I use Try no for? When it falls in except and the person type a string, it gives another error and terminates the program, in while I can use normally. I tried using a for loop with while, but the program does not repeat the option that was typed in the string but goes to the next one.
for k in range(1, 6):
try:
teste1 = float(input(f'test {k}: '))
teste.append(teste1)
except ValueError:
print('Erro, tente novamente')
teste1 = float(input(f'test {k}: '))
teste.append(teste1)
print(teste)
for each element of
for
, you need repeat endlessly the question until the user type correctly. Use awhile
within yourfor
.– nosklo