
John F. answered 02/01/20
Lawyer, Scientist, Programmer, and above all, Tutor
Hi Kristi!
If I understand correctly, there are three things that you need to do as part of this assignment:
- Print whether the number is even or odd.
- Print that number followed by the next 9 odd or even numbers after that.
- "The program must use .is_integer() method to display an error message."
You did great on the first part. Two quick things: (1a) the zero in {} is unnecessary, and (1b) your function only accounts for whole numbers. "3.2" is neither an odd nor even number. If you know the input is only integers, then this is not an issue. If the input is more than that, then you need another if statement thrown in there to handle those inputs.
For the second part, while a loop would have looked prettier, the manual method is perfectly fine for an assignment like this.
As for the third part, it is unclear (3a) when you are supposed to do the is_integer() check, and it is additionally unclear (3b) which error message you are anticipating. Overall, it seems to strictly be an exercise in understanding object types, since, again, the inputs are always expected to be integers.
For (3a), it seems that the assignment wants you to output both the print functions and the error. Because Python (and many other programming languages) execute code top-down, the print functions will have to come before the is_integer() check.
For (3b), a known error with is_integer() was "AttributeError: 'int' object has no attribute 'is_integer'". The reasoning is that this method only works on float-type objects.
This makes sense: there is no reason for an integer object to have an attribute that checks if that object is an integer - it would always be True if such a method existed.
Take a look at this StackOverflow answer that addresses why this is such a big deal, and how it was dealt with when migrating from Python2 (which treats numbers as integers by default) to Python3 (which treats numbers as floats by default):
https://stackoverflow.com/questions/17170226/is-integer-not-working
Hope this helps,
JAF