Question

Python 3 coding with AWS/IDLE. DDI&T a Python program to input, store, and process hourly temperatures for each hour...

Python 3 coding with AWS/IDLE.

DDI&T a Python program to input, store, and process hourly temperatures for each hour of the day (i.e., 24 temperatures). Your program should be divided logically into the following parts:

In function main() declare an empty List container:

         HourlyTemperatures = []    

Pass the empty HourlyTemperatures list to a function,

GetTemperatures(HourlyTemperatures)

         This function must interactively prompt for and input temperatures for each of the 24 hours in a day (0 through 23). For each temperature that is input, verify that its value lies in the range of minus 50 degrees and plus 130 degrees (i.e., validate your input values). If any value is outside the acceptable range, ask the user to re-enter the value until it is within this range before going on to the next temperature (HINT: use a nested loop (e.g., Python’s equivalent to a do-while loop) that exits only when a value in the specified range has been entered). Store each validated temperature in its corresponding element of the list container passed as a parameter to the function (Hint: Look at the ‘append(…)’ function that can be called on a list container).

Next pass the filled list container to a function,

ComputeAverageTemp(HourlyTemperatures)

         This function computes the average temperature of all the temperatures in the list and returns this average to the calling function.

Finally, pass the filled list container and the computed average temperature to another function,

                  DisplayTemperatures(HourlyTemperatures, AverageTemp)

         which displays the values of your temperature list in a columnar format followed by the values for the high temperature, low temperature, and average temperature for the day.  NOTE: If you want to create separate function(s) to find and return the high and low temperature values, then feel free to do so!

The resulting output should look something like this:

Hour                          Temperature

00:00                                42

01:00                                42

. . . . .                                . . . // Your program output must include all of these too!

22:00                                46

23:00                                48

High Temperature:          68

Low Temperature:           42

Average Temperature:    57.4

Since you have several created functions to perform each of the major steps of your solution, your main(): function should be quite simple. The pseudo code for main() might look something like this:

                  main()

                       #declare any necessary variable(s) and HourlyTemperatures list

                       while user-wants-to-process-another-days’-worth-of-temperatures

                           call GetTemperatures(HourlyTemperatures)

                                 call ComputeAverageTemp(HourlyTemperatures)

                                 call DisplayTemperatures(HourlyTemperatures, AverageTemperature)

                                 ask if user want to process another days’ worth of temperatures

  Test your program with at least two (2) different sets of temperatures. Make sure you enter values to adequately test your temperature-validation code (e.g., temperatures below –50 and above +130 degrees).

1 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Here is the completed code for this problem.  Let me know if you have any doubts or if you need anything to change.

Thank You !!

================================================================================================

def GetTemperatures(HourlyTemperatures):
    for i in range(24):
        while True:
            temperature=float(input('Enter temperature for {}:00 hours: '.format(i)))
            if -50<=temperature and temperature<=130:
                HourlyTemperatures.append(temperature)
                break
            else:
                print('Temperature cannot be less than -50 or greater than 130 degrees.')


def ComputeAverageTemp(HourlyTemperatures):
    return sum(HourlyTemperatures)/len(HourlyTemperatures)

def DisplayTemperatures(HourlyTemperatures, AverageTemp):
    high_temp=max(HourlyTemperatures)
    low_temp=min(HourlyTemperatures)
    print('{0:<20}{1:<15}'.format('Hour','Temperature'))
    for hour in range(10):
        print('0{0:<20} {1:<10}'.format(str(hour)+':00',HourlyTemperatures[hour]))
    for hour in range(10,24,1):
        print('{0:<21} {1:<10}'.format(str(hour)+':00',HourlyTemperatures[hour]))
    print('{0:<20}  {1:<10}'.format('High Temperature: ',high_temp))
    print('{0:<20}  {1:<10}'.format('Low Temperature: ', low_temp))
    print('{0:<20} {1:<10.1f}'.format('Average Temperature: ', AverageTemp))


def main():
    
    HourlyTemperatures = []
    GetTemperatures(HourlyTemperatures)
    average=ComputeAverageTemp(HourlyTemperatures)
    DisplayTemperatures(HourlyTemperatures,average)

main()

=======================================================================================

def GetTemperatures (HourlyTemperatures) for i in range (24): while True: temperature-float (input ( Enter temperature for :

C:\Users\UserlPycharmProjects Hour Temperatur 105 00:00 78 01:00 02:00 78 03:00 04:00 122 05:00 118 06:00 98 07:00 74 08:00 1

thanks !

Add a comment
Answer #2

def main():

    HourlyTemperatures=[]

    GetTemperatures(HourlyTemperatures)

    AverageTemp=ComputeAverageTemp(HourlyTemperatures)

    DisplayTemperatures(HourlyTemperatures,AverageTemp)

    ProcessAnotherDay()

def GetTemperatures(HourlyTemperatures):

    for x in range (24):

        x=int(x)

        x+=1

        while True:

            x = str(x)

            try:

                temp=float(input("Enter Temperature for {}:00 o'clock - ".format(x.zfill(2))))

            except ValueError:

                print('Please enter a value')

            if -50<=temp and temp<=130:

                HourlyTemperatures.append(temp)

                break

            else:

                print('Temperature has to be above -50 degrees and below 130 degrees please enter another temperature.')

def ComputeAverageTemp(HourlyTemperatures):

    return sum(HourlyTemperatures)/len(HourlyTemperatures)

def DisplayTemperatures(HourlyTemperatures,AverageTemp):

    HighTemp=max(HourlyTemperatures)

    LowTemp=min(HourlyTemperatures)

    print('{0:<10}{1:^10}'.format('Hour','Temperature'))

    for y in range(10):

        print('0{0:<1}:00{1:^20}'.format(y,int(HourlyTemperatures[y])))

    for y in range(10,24,1):

        print('{0:<1}:00{1:^20}'.format(y,int(HourlyTemperatures[y])))

    print('Highest Temperature is: ',int(HighTemp))

    print('Lowest Temperature is: ',int(LowTemp))

    print('Average Temperature is: ',AverageTemp)

def ProcessAnotherDay():

    while True:

        yesno = input('Do you want to process another day?')

        if yesno == 'y':

            main()

        if yesno == 'n':

            break

        if yesno != 'y' and 'n':

            print('Enter y for YES, Enter n for NO')

main()


source: Python
answered by: Gavin
Add a comment
Know the answer?
Add Answer to:
Python 3 coding with AWS/IDLE. DDI&T a Python program to input, store, and process hourly temperatures for each hour...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 3 coding with AWS/Ide. Objective: The purpose of this lab is for you to become familiar with Python’s built-in te...

    Python 3 coding with AWS/Ide. Objective: The purpose of this lab is for you to become familiar with Python’s built-in text container -- class str-- and lists containing multiple strings. One of the advantages of the str class is that, to the programmer, strings in your code may be treated in a manner that is similar to how numbers are treated. Just like ints, floats, a string object (i.e., variable) may be initialized with a literal value or the contents...

  • You can vary it as long as the fahr and cels temperatures line up vertically and everything is clearly labeled. This program involves inputting a set of Fahrenheit temperatures and performing a set...

    You can vary it as long as the fahr and cels temperatures line up vertically and everything is clearly labeled. This program involves inputting a set of Fahrenheit temperatures and performing a set of operations on them: The number of temperatures to input is determined by the user at the beginning of the program. You must ask them to enter the number of temperatures that they will be typing in. This number must be between 1 and 30 (inclusive.) If...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...

  • Write a Python program that asks the user to type in their three quiz scores (scores...

    Write a Python program that asks the user to type in their three quiz scores (scores between 0 and 100) and displays two averages. The program should be written so one function gets the user to input a score, another function takes the three scores and returns the average of them. And another function takes the three scores and averages the two highest scores (in other words, drops the lowest). Each of these functions should do the computation and return...

  • Change your C++ average temperatures program to: In a non range-based loop Prompt the user for...

    Change your C++ average temperatures program to: In a non range-based loop Prompt the user for 5 temperatures. Store them in an array called temperatures. Use a Range-Based loop to find the average. Print the average to the console using two decimals of precision. Do not use any magic numbers. #include<iostream> using namespace std; void averageTemperature() // function definition starts here {    float avg; // variable declaration    int num,sum=0,count=0; /* 'count' is the int accumulator for number of...

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

  • Problem: You will write a program to compute some statistics based on monthly average temperatures for...

    Problem: You will write a program to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for 1901, the...

  • MUST BE WRITTEN IN C++ All user input values will be entered by the user from...

    MUST BE WRITTEN IN C++ All user input values will be entered by the user from prompts in the main program. YOU MAY NOT USE GLOBAL VARIABLES in place of sending and returning data to and from the functions. Create a main program to call these 3 functions (5) first function will be a void function it will called from main and will display your name and the assignment, declare constants and use them inside the function; no variables will...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as...

    Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT