I'm trying to create an ROI calculator. I want to accept the input in only int format. I've created a try-except block to avoid inputs in other formats. However, my logic fails if any user enters an incorrect input (e.g. str) in either Rent or Loss.
If they do that, the while loop starts asking for the input from Investment again. I want to bypass that, and let the code ask for the input from that respective variable itself, be it Rent or Loss. Any suggestions, please?
print('This is a ROI calculator. Please enter below details:')
while True:
try:
Investment=int(input('Investment:'))
Rent=int(input('Rent/month:'))
Loss=int(input('Loss/year:'))
if Loss:
break
except ValueError:
print('Please enter in a number format only')
def ROI(Investment,Rent,Loss):
Net_profit=int((Rent*12) - Loss)
ROI=((Net_profit/Investment)*100)
ROI=round(ROI,2)
print(f'Your Return on Investment is: {ROI}')
ROI(Investment,Rent,Loss)