#Python HW help needed.

7 messages · Page 1 of 1 (latest)

sour pulsar
#

In hurricane season, we would like to keep track of the severity of the weather. We will invent a measure of weather severity that combines the wind speed, and rain fall.

Ask the user to enter data on the wind and rain for several days ending with -1.0 (sentinel value).

The program will use a sentinel controlled loop. The program will count the number of days entered, and that count is included in the output.

#

whenever use the data thats needed, im not getting what the output data the prof has as "correct". im not sure how to fix this.

his output
The average rain is 1.9 inches

The average wind is 35.0 mph

The weather severity for these 3 readings is: 54.0

my output:The average rain is 35.0 inches
The average wind is 1.9 mph
The weather severity for these 3 readings is: 351.9

#

the data used is:
0.2 25

1.0 35

4.5 45

-1.0

#

rain_sum = 0.0
wind_sum = 0.0
count = 0

while True:
data = input("Enter the wind speed and rain fall for a day (enter -1 to exit): ")
if data == "-1":
break
else:
wind, rain = map(float, data.split())
wind_sum += wind
rain_sum += rain
count += 1

if count == 0:
print("No data entered.")
else:
avg_wind = wind_sum / count
avg_rain = rain_sum / count
severity = (avg_rain * 10) + avg_wind

print(f"The average rain is {avg_rain:.1f} inches")
print(f"The average wind is {avg_wind:.1f} mph")
print(f"The weather severity for these {count} readings is: {severity:.1f}")
slow salmon
#

Your error is actually very obvious, you might be overthinking this. Think about this:

His output has 1.9 for rain and 35 for wind.
You have 1.9 for wind and 35 for rain.

What do you notice?

lavish jasper
#

good catch!

sour pulsar
#

oh my god.. i dont know how i didnt even catch that. thank you. im now getting the desired output