Apr-29-2019, 10:03 PM
I don't think the word "always" should be applied very liberally, and definitely not in this case. Your example definitely doesn't need it, since the if-branch already returns.
This is beside the point, but there's several issues I have with your example.
- You return bad values (-1) if the passed number isn't an int. The meaning you've described the function to have with the first three lines is that you're simply returning an int, which means valid usage would look something like:
- The name, itself,
This is beside the point, but there's several issues I have with your example.
- You return bad values (-1) if the passed number isn't an int. The meaning you've described the function to have with the first three lines is that you're simply returning an int, which means valid usage would look something like:
current_inventory += check_int(received_quantity)
, which could cause the inventory to decrease just because the user passed bad info?- The name, itself,
check_int()
, implies that you're checking for the validity of something. ...which is what True/False is for. Just from looking at the function's signature, I'd guess that the correct usage would be this:received_quantity = # get something from the user if check_int(received_quantity): current_inventory += received_quantity