Python Forum
Functions with conditionals and comparison operators
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Functions with conditionals and comparison operators
#7
First of all, let me say that
if (a % 2 and b % 2) != 0:
and
if a % 2 and b % 2:
have same outcome, as you can see
for a, b in ((3, 5), (2, 5), (5, 2), (4, 2)):
    print((a%2 and b%2) != 0)
    print(a%2 and b%2)
Output:
True 1 False 0 False 0 False 0
I didn't claim it will do what is required in the exercise, just it will do the same as the original code.

def min_max(a, b):
    if a%2 or b%2: # at least one is odd
        return max(a,b)
    else:
        return min(a, b)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Functions with conditionals and comparison operators - by buran - Dec-27-2018, 09:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Meltdown Mitigation (operators + conditionals) beware: Exercism potential spoiler Drone4four 5 2,700 Feb-21-2022, 08:49 AM
Last Post: Gribouillis
  Need help with a homework problem on logical operators voodoo 3 4,636 Jun-28-2019, 03:45 PM
Last Post: jefsummers
  Guessing game with comparison operators Drone4four 9 13,869 Dec-02-2018, 06:12 PM
Last Post: ichabod801
  Nested Conditionals Elero 3 7,988 Apr-16-2018, 07:58 PM
Last Post: Elero
  Error with conditionals RiceGum 17 7,333 Oct-18-2017, 01:45 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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