Skip to content Skip to sidebar Skip to footer

Data Validation - Python 2.7

This is the code that I have edited so far for the upcoming AS computing Preliminary code. It's homework and I am stuck as to why it does not work. Any suggestions? Thanks def Get

Solution 1:

you should just do key = raw_input(...) rather than key = int(raw_input(...))

With the former, key is a string until you try to make it an integer. With the latter, you attempt to construct an int from it right away without guarding that attempt with any exception handling.


There are some other logic flaws as well. Right now, your infinite while loop doesn't do anything for example. (you return after the first pass no matter what). Moving the return statment where the break is would probably* make it do what you want. Also, you don't do anything with the int that you construct (i), although it's unclear whether or not you should be returning it or key.

*I'm making assumptions about what your program is supposed to do here...

Post a Comment for "Data Validation - Python 2.7"