Skip to content

[issue#2180]:convert wind direction to degrees #2248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions convert_wind_direction_to_degrees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def degrees_to_compass(degrees):
directions = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
index = round(degrees / 45) % 8
return directions[index]

# Taking input from the user
while True:
try:
degrees = float(input("Enter the wind direction in degrees (0-359): "))
if degrees < 0 or degrees >= 360:
raise ValueError("Degrees must be between 0 and 359")
break
except ValueError as ve:
print(f"Error: {ve}")
continue


compass_direction = degrees_to_compass(degrees)
print(f"{degrees} degrees is {compass_direction}")