Ask coding questions

← Back to all posts
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
EchoCoding (262)

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

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

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

EchoCoding (262)

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

a5rocks (793)

This is just a bunch of ifs. I'm sure you can do it.

ayaanHasan (2)

@a5rocks I am very new to this i am trying my best however there is something just wrong

mkhoi (291)

@ayaanHasan Can you send the code?

a5rocks (793)

@ayaanHasan what language are you making this for? I recommend googling / whatever-search-engine-you-use-ing for a tutorial on:

  • functions
  • if statements
  • how to get a variable's class
YipCubed (6)

What have you done so far? What seems to be the problem? What language are you working in?

Have a look at for an overview of if-else statements and then come back with more questions.


rediar (349)

Try using if, and, else, elif!
please upvote or mark as answer if helpful