In: Computer Science
Implement the following function in the PyDev module functions.py and test it from a PyDev module named :
def wind_speed(speed): """ ------------------------------------------------------- description Use: category = wind_speed(speed) ------------------------------------------------------- Parameters: speed - wind speed in km/hr (int >= 0) Returns: category - description of wind speed (str) ------------------------------------------------------ """
Wind speeds are categorized as:
Wind speed (km/h) | Category |
---|---|
< 39 | Breeze |
39 - 61 | Strong Wind |
62 - 88 | Gale Winds |
89 - 117 | Whole Gale |
> 117 | Hurricane |
The function should return 'unknown' for a negative wind speed.
Sample testing:
Wind speed (km/h): 95 Category: Whole Gale
Make a module in PyDev in this manner:
1) Go to Window> Perspective> Open Perspective > PyDev(default)
2) Create a new package File> new > PyDev package
Check if .py files are associated with Python editor by going to: Windows> Preferences>General>Editors>File Asociations
3) Go to File> New> PyDev Module and fill module name
4) Press Finish
Here is the function:
def wind_speed(speed):
if speed<39:
category='Breeze'
elif speed>=39 and speed<=61:
category='Strong Wind'
elif speed>=62 and speed<=88:
category='Gale Winds'
elif speed>=89 and speed<=117:
category="Whole Gale"
elif speed>117:
category="Hurricane"
elif speed<0:
category="unknown"
return category
For calling the function:
speed=int(input("Enter wind speed"))
print(type(speed))
category=wind_speed(speed)
print("Wind speed(km/h",speed)
print("Category:",category)
This will return the sample output:
Wind speed (km/h): 95 Category: Whole Gale