0
How do I repeat the above question in case the answer does not get any of the options within the function if
and elif
?
parcelax = int(input('Qual formato de parcelamento? \n 1) Á Vista \n 2) 12x \n 3) 30x \n 4) 60x \n'))
valor1 = 1
if (parcelax == 1):
valor1 = valor
elif (parcelax == 2):
valor1 = valor / 12
elif (parcelax == 3):
valor1 = valor / 30
elif (parcelax == 4):
valor1 = valor / 60
else:
print('Digito incorreto!\n Digite valor Valido!')
print('Valor de parcela até o momento é de: R${:.2f}!'.format(valor1))
and I’m doing the post because I’ve done countless searches and none of them could find a solution for my case in specific.
Your case isn’t that specific and the question you check answers what you need: if you want to read the user input while it’s not a valid value, just make an infinite loop. Study about Python repetition structures, be the
while
orfor
and try to implement in your code. If you still can’t, you can go back, [Dit] the question and demonstrate why your question would be different from the other existing ones. It is not just because it is a different piece of code that the problem is different.– Woss
I studied the while repeating structures, and even tried to do through if - lse, but from syntax error all the ways and I don’t even know what I’m missing, I rewrite all the code, every time, so I came here to take the doubt of where I’m going wrong or if I’m using it incorrectly, but that’s it, if my question is going to be marked as duplicate, just thank you.
– Gabriel Ferreira