GradePack

    • Home
    • Blog
Skip to content

When dealing with paired data, X is always the dependent var…

Posted byAnonymous May 6, 2026May 7, 2026

Questions

When deаling with pаired dаta, X is always the dependent variable and Y is always the independent variable.

Write а Pythоn prоgrаm thаt perfоrms the task outlined below: Weather Report Automation You work for a national weather service that wants to automate the process of reporting temperatures across cities. Your task is to write a small program that reads a list of city names from a file, generates a random temperature for each city, writes a report classifying each city's temperature, and prints a histogram summarizing the results. The program will: Read city names from a text file (you can assume the input cities.txt file is not erroneous) Generate a random temperature (in Fahrenheit) between -20 and 110 for each city Use a function to determine the temperature classification for a given temperature Write a report.txt back to disk with each city's name, temperature, and classification Print a histogram to the console showing how many cities fall into each temperature classification Your read and write functions must both raise FileNotFoundError exceptions using try/except AND ensure the file connection is properly closed — either via a finally block or the with statement. The main function should handle any exceptions raised by the functions. Use only the features we've covered in this course from the first 7 chapters. Functions to be coded Don't try to do all these at once — get read_cities working first and print the results in main, then move on. 1. read_cities — takes a filename string and returns a list of strings; connect to the file, read each city name line by line, remove whitespace/newlines from each name, and return the list. Remember: your function must raise FileNotFoundError exceptions using try/except AND ensure the file connection is properly closed via a finally block or with statement. 2. generate_temperatures — takes a list of city names and returns a list of integers; for each city in the list, generate a random integer between -20 and 110 (inclusive) and append it to a new list. Return the list of temperatures. The returned list should be the same length as the cities list so that each city lines up with a temperature by position. 3. get_classification — takes a temperature (integer) and returns a string classification according to the following scale: Temperature Classification 85 and above Hot 70 and above Warm 50 and above Mild 32 and above Cold Below 32 Freezing 4. write_report — takes an output filename string, a list of city names, and a list of temperatures, and returns nothing; open the output file for writing, then iterate over each city using their index position to access both the city name and the corresponding temperature from the two lists. Call get_classification() to determine the classification and write a line in the following format: Phoenix: 97 - Hot Don't forget to add a newline after each line using + "n". Remember: your function must raise a FileNotFoundError exception using try/except AND ensure the file connection is properly closed via a finally block or with statement. 5. print_histogram — takes a list of temperatures and returns nothing; count how many cities fall into each classification by calling get_classification() on each temperature and tallying the results. Then print a labeled histogram to the console where each classification is displayed with a row of stars (*) representing its count. The output should be formatted so that all labels and bars are neatly aligned. For example: Temperature Classification Histogram========================================Hot        | *** (3)Warm       | **** (4)Mild       | *** (3)Cold       | ** (2)Freezing   | *** (3)======================================== Pseudocode for main main:    call read_cities("cities.txt") and save the result into a variable    call generate_temperatures(), passing the list of cities, and save the result into a variable    call write_report("report.txt", list of cities, list of temperatures)    call print_histogram(), passing the list of temperatures You should then see a report.txt file appear in your directory, and the histogram printed to the console. Note that since temperatures are randomly generated, your output will differ from the examples above — what matters is that the format is correct and the classifications match the temperatures according to the scale above. Remember to handle any exceptions raised by read_cities and write_report, and print the original error message from the exception. Notes Please create cities.txt using the following list of city names: PhoenixSeattleMiamiDenverChicagoNew YorkLos AngelesHoustonBostonAtlantaMinneapolisSan DiegoDallasPortlandNashville Sample Run Console Output Temperature Classification Histogram========================================Hot        | ** (2)Warm       | **** (4)Mild       | *** (3)Cold       | **** (4)Freezing   | ** (2)======================================== report.txt Output Phoenix: 91 - HotSeattle: 48 - ColdMiami: 85 - HotDenver: 33 - ColdChicago: 71 - WarmNew York: 58 - MildLos Angeles: 76 - WarmHouston: 54 - MildBoston: 28 - FreezingAtlanta: 73 - WarmMinneapolis: 17 - FreezingSan Diego: 70 - WarmDallas: 44 - ColdPortland: 51 - MildNashville: 38 - Cold If cities.txt Is Not Found (Error Case) If cities.txt is missing, the program would print the following and exit gracefully without crashing: Error: [Errno 2] No such file or directory: 'cities.txt' Similarly, if report.txt cannot be written (e.g. due to a permissions error), the program would print: Error: [Errno 13] Permission denied: 'report.txt'

The nurse is cаring fоr а client оn the pоstpаrtum unit who had an operative vaginal delivery. The client is complaining of severe perineal pain of 9 on a 10-point scale after receiving ibuprofen and an opioid. The pulse is 110 beats per minute. The nurse suspects the client 

Tags: Accounting, Basic, qmb,

Post navigation

Previous Post Previous post:
The set A and its complement are never mutually exclusive.
Next Post Next post:
A research team is investigating people that wear corrective…

GradePack

  • Privacy Policy
  • Terms of Service
Top