Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following is in Python. Any help would be highly appreciated! This is the existing code given: import os def read_file(): ''' Prompt user for

The following is in Python. Any help would be highly appreciated!

image text in transcribed

image text in transcribed

This is the existing code given:

import os

def read_file(): ''' Prompt user for a file containing a 5 day forecast and then print it out. ''' def write_file(): ''' Prompt the user for a file to write to. Prompt for a 5 day forecast and write the contents to the file. ''' def print_menu(): print() print("1. Read File") print("2. Write File") print("3. Exit")

i = -1 while i not in [1, 2, 3]: i = int(input("Choose: ")) return i

def main(): print("Welcome to the Weather Monitor!")

i = print_menu() while i != 3: if i == 1: read_file() elif i == 2: write_file() i = print_menu()

if __name__ == '__main__': main()

File I/O Lab Overview In this lab, you will learn modify an existing program to read and write files. Contents Overview Contents Files Instructions Files . file lab.py Instructions You have been tasked with finishing a program to read and write 5-day forecast data. Right now the program consists of a menu with stub functions for each option. When a user selects Read File' the program should prompt the user for a filename and then print the contents of the file. If a user selects 'Write File' the program should prompt the user for a filename, prompt the user for 5 days worth high temperatures, and then write that data to the text file Data should be written to the text file in the following format: Day 1: 87 Day 2: 75 Day 3: 78 Day 4: 80 Day 5: 81 Design your program to match the sample execution below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions