Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python python easy question...

briank282

New Coder
hi i need help the ;last part is not retunred and i have no idea... thank you

According to this xkcd cartoon you shouldn't date someone whose age is less than half your own age plus 7. Write a boolean-valued function can_date(age1, age2) that takes the ages of two people and return True if they can date, according to xkcd's rule.

Notes:

  • The ages are not in any particular order - the bigger one may be either first or last.
  • Assume integer division so that, for example, a 19-year-old can date a 16-year-old because we take half of 19 to be 9 not 9.5.

def can_date(age1, age2):
"""return"""
if age1 // 2 + 7 == age2:
return True
elif age2 // 2 + 7 == age1:
return True
elif age1 == age2:
return True
else:
return False


everthing returns except the all good :)

print(can_date(24, 19))
TrueTrue
print(can_date(19, 24))TrueTrue
print(can_date(24, 18))FalseFalse
print(can_date(16, 16))TrueTrue
print(can_date(14, 16))FalseFalse
print(can_date(16, 15))TrueTrue
print(can_date(73, 43))TrueTrue
print(can_date(42, 73))FalseFalse
run_lots_of_tests()All good :)can_date(1, 1) returned True, should be False
 
hi i need help the ;last part is not retunred and i have no idea... thank you

According to this xkcd cartoon you shouldn't date someone whose age is less than half your own age plus 7. Write a boolean-valued function can_date(age1, age2) that takes the ages of two people and return True if they can date, according to xkcd's rule.

Notes:

  • The ages are not in any particular order - the bigger one may be either first or last.
  • Assume integer division so that, for example, a 19-year-old can date a 16-year-old because we take half of 19 to be 9 not 9.5.

def can_date(age1, age2):
"""return"""
if age1 // 2 + 7 == age2:
return True
elif age2 // 2 + 7 == age1:
return True
elif age1 == age2:
return True
else:
return False


everthing returns except the all good :)

print(can_date(24, 19))
TrueTrue
print(can_date(19, 24))TrueTrue
print(can_date(24, 18))FalseFalse
print(can_date(16, 16))TrueTrue
print(can_date(14, 16))FalseFalse
print(can_date(16, 15))TrueTrue
print(can_date(73, 43))TrueTrue
print(can_date(42, 73))FalseFalse
run_lots_of_tests()All good :)can_date(1, 1) returned True, should be False
You have told the program to return `True` if the numbers equal each other. This code should work.

Python:
def can_date(age1, age2):
    """return"""
    if age1 // 2 + 7 == age2:
       return True
    elif age2 // 2 + 7 == age1:
       return True
    elif age1 == age2:
       return False
    else:
       return False
 
Back
Top Bottom