Reputation: 27
I'm trying to finish up an assignment for class, but I'm just not getting this last piece.
I'm trying to have a function that, when given the wind speed, gives the associated warning message, but the trick is that the wind speed and warning messages and parameters are in 2 previously defined functions. Also, the teacher wanted us to call both functions all in one line.
So first I created the first 2 functions:
def storm_category(speed):
if speed <= 129:
return (0)
if speed >= 130 and speed < 164:
return (1)
if 165 <= speed and speed < 189:
return (2)
if 190 <= speed and speed < 219:
return (3)
if 220 <= speed and speed < 259:
return (4)
if speed >= 260:
return (5)
def category_warning(category):
if category == 0:
return "Not a major threat"
if category == 1:
return "Very dangerous winds will produce some damage."
if category == 2:
return "Extremely dangerous winds will cause extensive damage."
if category == 3:
return "Devastating damage will occur."
if category == 4:
return "Catastropic damage will occur"
if category == 5:
return "Cataclysmic damage will occur."
But in the last function I'm required to use information from both:
def warning(speed):
# Requirement: this function should be one line!
return storm_category(category_warning)
With the above code though, every time I try to return a I get an error saying that "builtins.TypeError: '<=' not supported between instances of 'function' and 'int'". It says that the errors are on these lines:
return storm_category(category_warning)
And
if speed <= 129:
return (0)
I'm not sure if my syntax is wrong or what. Can anyone help me?
Upvotes: 0
Views: 1095
Reputation: 540
the error is because you send the name of function and not the function call. must be:
def warning(speed):
return category_warning(storm_category(speed))
note: in your code when the python interpreter process the operation
speed <= 129
, the python interpreter assumes speed is a callable function.
Upvotes: 1