Read file and write even and odd numbers to separate files - clone Read the file of numbers and put the even and odd numbers in separate files. use python Perform the following operations • Read the console input and create a file. • $ in the console input is considered as an end of content for a file. • Close the file after creation. • Read the file and put even and odd numbers in separate file even.txt and odd.txt respectively. • Display the content of even.txt and odd.txt. Input 73771782 79982321 76259734 94432075 50063976 42311916 $ where • '$' character indicates an end of content for a file. Output even.txt 73771782 76259734 50063976 42311916 odd.txt 94432075 79982321
Added by Debra S.
Close
Step 1
We can use the built-in `input()` function to get the console input and the `open()` function to create a file. We can use a while loop to keep getting input until the user enters the '$' character. ```python with open('numbers.txt', 'w') as f: while True: Show more…
Show all steps
Your feedback will help us improve your experience
Oswaldo Jiménez and 76 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a program that outputs the cube of odd numbers between 1 and 20 and stores them in a file named "cube_numbers.txt". Your output for the first 3 odd numbers is given below: 1 27 125 *IN python
Liam H.
Write a Python Program for finding even odd number?
Chandra J.
IN JAVA. 1) Write a program named KeyboardToFile that reads all the data in standard input and makes an exact, perfect copy of it in a file named input.copy. 2) Write a program named KeyboardTo2Files that reads all the integers in standard input and writes the even ones to a file named evens.txt and the odd ones to a file named odds.txt. Each integer written out should be on a line by itself, with nothing else on the line. 3) The file numbers.text consists of integers. Write a program named ParityCounter that reads the data and then prints (to standard output) the number of even integers and number of odd integers read (excluding the header of course). For example, if the file numbers.text contains: 3 8 27 5 44 67, the program should produce the following output: 3 even integers 1 odd integer.
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD