Skip to content

Commit

Permalink
Create convert_wind_direction_to_degrees.py
Browse files Browse the repository at this point in the history
added new program that convert wind direction in degree to compass direction
  • Loading branch information
Anxhul10 committed Jun 18, 2024
1 parent b030528 commit 2cfa37f
Showing 1 changed file with 19 additions and 0 deletions.
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}")

0 comments on commit 2cfa37f

Please sign in to comment.