Reputation: 75
I am trying to design a function that returns whether a or b is longer but I'm having a syntax error.
def get_longer(a:str, b:str):
return a if len(a) >= len(b) else return b
I have tried with a print statement and it is working however I need it to work with a return statement.
Any suggestions?
Upvotes: 4
Views: 7809
Reputation: 842
You can try the following code.
def get_longer(a:str, b:str) -> str:
if (len(a) >= len(b)):
return a
else:
return b
Upvotes: 0
Reputation: 1132
You have an extra return
statement
def get_longer(a:str, b:str):
return a if len(a) >= len(b) else b
Upvotes: 6