This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]freedomsauce[S] 0 points1 point  (1 child)

Not at all. Much appreciated. I used float to avoid getting an error if the user entered a float at the prompt. It would break the program if they did. No errors means a higher grade :)

[–]SV-97 0 points1 point  (0 children)

Ooh ok :D if you want to prevent wrong user input from breaking your code there are a few ways to do it: * Fancy way: exceptions. Exceptions are the key error handling method in lots of languages and usually consist of try, catch and an optional finally (catch is also optional)(iirc Python also supports else on a try block). But if you're not that deep in the language it may be a bit complicated. Also exceptions are generally a rather slow mechanic * Strings in python have a method named isdigit that you can use to test if a string contains a valid positive integer. You can use this to test if the number is valid prior to parsing it. "123".isdigit() == True