2
can I get help with this question please
ayaanHasan (2)

Write a function isOldEnough that takes an input called num as an argument. The function should return either true or false based on the following logic:

  1. It returns true if the number is greater than or equal to 18
  2. It returns false if the number is non-negative but less than 18
  3. It returns "Invalid argument" if the number is negative or if it's not a number at all
You are viewing a single comment. View All
8
EchoCoding (242)

@ayaanHasan I quickly wrote this, let me know if it solved your problem!

def isOldEnough():
  try:
    if num > 0:
      if num >= 18:
        print(True)
      elif num < 18:
        print(False)
  except ValueError:
    print("Invalid Argument.")
isOldEnough()
1
ayaanh22 (0)

@EchoCoding thank you for your help. However the code you sent is not working for some reason.

6
EchoCoding (242)

@ayaanh22 How is it not working? It prints True of False depending on the scenario.