Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions Deliverables : You must submit your .py file. Name the file: lastname_firstname_lab3.py. Example: coleman_marie_lab3.py Perform the following steps in the file you created above

Instructions

Deliverables: You must submit your .py file. Name the file: lastname_firstname_lab3.py.

Example: coleman_marie_lab3.py

Perform the following steps in the file you created above (lastname_firstname_lab3.py):

Open the file provided file for reading.

Create a loop to move through each line of the file contents in order to determine if the current number is even or odd. Based on the findings, build two string variables contain a list of even and odd numbers. Add a " " to the end of each number

Close the file after the loop ends.

Open two new files for writing and write the odd numbers to one and the even numbers to the other

HINT: Use the modulo operator % with a 2 to determine if the current number is even or odd.

Additional Instructions:

All of your code should reside inside of a TRY/Except code block. Check for a "FileNotFoundError" error. Do not shortcut the steps. Do not write the numbers to the two new odd/even files inside the same loop where you're reading from the provided file. Write your code to follow the sequence of steps "as listed" in the instructions.

There's no need to loop through the two variables. You can just write the variable content to their respective files in a single line. Don't forget to close the files afterwards.

Sample input / output: Your program should match the sample output below:

2 8 11 15 17 22 28 36 41 44 48 59 62 63 71 78 80 84 87 91 92 105

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

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago