0
I am unsure why my program behaves how it does when I input words where it should receive numbers. I'm using try and except.
My code runs as expected when I input propper inputs but when I input words where it should be numbers it starts to behave weirdly. It should call main and ask for user input again when the try except fails. It seems to instead ask for the same input multiple times or input it shouldn't ask for. https://code.sololearn.com/c8dKcgQW8TE6/?ref=app
2 Antworten
+ 5
Replace every main() with return main(). Otherwise, it'll call the main function again but still try to use the invalid values after that. return main() will actually interrupt the main function and start from the beginning (I hope this explanation makes sense)
0
It makes perfect sense. I can't say I exactly understand the why of it but I understand it trying to rerun with bad values again.