Answer to Question #108127 in Python for Fahd

Question #108127
You have been tasked to write an algorithm in pseudocode, flowchart or program code to find the highest and lowest noon temperature in one year. Your algorithm should:
input the temperature at noon once a day for one year
find the highest temperature
find the lowest temperature
calculate the average temperature for the year
outputs the average, highest and lowest temperatures for the year
You should include appropriate prompts for data entry.
1
Expert's answer
2020-04-06T12:08:27-0400
import statistics

months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
          'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
year = 2020
temperatureList = []

for month in months:
    if month in ['JAN', 'MAR', 'MAY', 'JUL', 'AUG', 'OCT', 'DEC']:
        length = 31
    elif month in ['APR', 'JUN', 'SEP', 'NOV']:
        length = 30
    else:
        if year // 4 == 0:
            length = 29
        else:
            length == 28

    for day in range(1, length + 1):
        print('DATE:', month, day)
        while True:
            try:
                temperature = float(input('Enter noon temperature: '))
                temperatureList.append(temperature)
                break
            except ValueError:
                print('Invalid input. Try again...')

print()

temperatureList.sort()
lowestTemperature = temperatureList[0]
highestTemperature = temperatureList[-1]
averageTemperature = statistics.mean(temperatureList)

print('Lowest Temperature:', lowestTemperature)
print('Highest Temperature:', highestTemperature)
print('Average Temperature:', averageTemperature)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS