Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I am working on a project for python and I would like some help with these two functions, thanks. a) def open_file(): Prompts the

Hi, I am working on a project for python and I would like some help with these two functions, thanks.image text in transcribed

a) def open_file(): Prompts the user to enter a year number for the data file. The program will check whether the year is between 1990 and 2019 (both inclusive). If year number is valid, the program will try to open data file with file name 'yearXXXX.txt', where XXXX is the year. Appropriate error message should be shown if the data file cannot be opened or if the year number is invalid. The year is invalid if it is not a number between 1990 and 2019, inclusively. The invalid year error is shown in this case. If the loop is correct but the file does not exist, the other error will be output. This function will loop until it receives proper input and successfully opens the file. It returns a file pointer and year. Hint: use string concatenation to construct the file name. i. Parameters: None ii. Display: prompt and error message iii. Return: file pointer and int b) def handle_commas (s,T) int or float or None The parameters are s, a string, and T, a string. The expected values of T are int and float; any other value returns None. If the value of T is int, the string s will be converted to an int and that int value will be returned. Similar for float. If a value of s cannot be converted to an int or float, None will be returned (hint: use try- except). Note: this is the same function we had in Project 5. i. Parameters: str, str ii. Display: nothing iii. Returns: int or float or None

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

1. What is meant by Latitudes? 2. What is cartography ?

Answered: 1 week ago

Question

What is order of reaction? Explain with example?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago