Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TO ELSE OR NOT TO ELSE?
#2
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: 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
Reply


Messages In This Thread
TO ELSE OR NOT TO ELSE? - by rxndy - Apr-27-2019, 02:04 AM
RE: TO ELSE OR NOT TO ELSE? - by nilamo - Apr-29-2019, 10:03 PM
RE: TO ELSE OR NOT TO ELSE? - by rxndy - Apr-30-2019, 02:11 AM
RE: TO ELSE OR NOT TO ELSE? - by buran - Apr-30-2019, 07:13 AM
RE: TO ELSE OR NOT TO ELSE? - by rxndy - Apr-30-2019, 11:42 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020