Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images
Thank you!
The same homework with different requirements(below). what is code?
Ask user to enter file containing floating point numbers
Open and read file into a list of strings and assign to lines
For each line in lines
Split the line into individual floating point numbers and assign to tokens
Assign 0 to total
Assign first number to smallest
Assign first number to largest
For each token in tokens
Convert to a floating point number and assign to number
Add number to total
If number is less than smallest, assign number to smallest
If number is greater than largest, assign number to largest
Calculate average
Display total, average, smallest number, largest number
when I run geany, it showed"
File
file = open("input.txt", "r")
FileNotFoundError: [Errno 2] No such file or directory: 'input.txt'", how to fix it ?
Thank you!
The same homework with different requirements(below). what is code?
Ask user to enter file containing floating point numbers
Open and read file into a list of strings and assign to lines
For each line in lines
Split the line into individual floating point numbers and assign to tokens
Assign 0 to total
Assign first number to smallest
Assign first number to largest
For each token in tokens
Convert to a floating point number and assign to number
Add number to total
If number is less than smallest, assign number to smallest
If number is greater than largest, assign number to largest
Calculate average
Display total, average, smallest number, largest number
when I run geany, it showed"
File
file = open("input.txt", "r")
FileNotFoundError: [Errno 2] No such file or directory: 'input.txt'", how to fix it ?
- In c++ write a code that tells a user to enter a filename and read that text file line by line.arrow_forwardin pythonarrow_forwardCan you help me write a C++ Program that does the following: Create a program that reads a file containing a list of songs andprints the songs to the screen one at a time. After each song is printed,except for the last song, the program asks the user to press enter for more.After the last song, the program should say that this was the last song andquit. If there were no songs in the file to begin with, the program shouldsay that there are no songs to show and quit.The program should begin by asking the user for the name of the input file.Each song consists of a title, artist and year.In the file, each song is given on three consecutive lines.Create this program using the latest version of the class Song you created. The latest version of the class song I created is below: #include <iostream>#include <string>using namespace std;class Song {private: string Title; string Artist; int Year;public: Song() : Title("invalid"), Artist("invalid"), Year(-1) {} Song(const string…arrow_forward
- Chapter 4. PC #6. File Letter Counter (page 264) Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Class name: FileLetterCounter Hints: Hint 1. To read a single character from the keyboard, you need to read a full line and then take the first character in position 0. Hint 2. To count the occurrences of a given characters in a file you need to read the file line-by-line using a while loop, then for each line check all characters in all positions and increment the character counter for each occurrence. This will require to have a for-loop nested inside the while-loop.arrow_forwardComputer Science C++ Create a text file "input.txt" with a certain amount of integers (you decide how many). Write a program that reads these numbers from the file, adds them, and when you have reached the end of the file, calculates the average of these numbers. Print a message and the average to the console. Code this program twice, demonstrating the two methods to detect the end of the file, part A: reading a value from Instream and storing it (boolean expression) in the while loop part B: using the eof() member functionarrow_forwardQ1: Write a python code to read data from a file "file1.txt" and then write the data to another "file "file2.txt 4:30arrow_forward
- In Python, Create a program that will write 100 integers created randomly in a file. The integers will be separated by a space in the file. Read the data back from the file, and display the sorted data. The program should prompt the user to enter a file name. Utilize the following function headers for this problem: Main() WriteNumbers(filename) ReadNumbers(filename) The main function will first prompt the user to enter the filename. Then the main function calls WriteNumbers-then ReadNumbers. The WriteNumbers function opens an output file and writes 100 random numbers as long a large string text. Do not use lists for this problem- please just write a random number followed by a space 100 times. The ReadNumbers function will then read the text file and display the numbers sorted. In order to sort the numbers, read the big string and then split it into a list. Now convert them into integers by using list comprehension and then sort the list. Loop through the list and print each…arrow_forwardIn Python, Write a program that prompts the user for a file name. (Use problem 2.txt file) Each line of the file should be preceded by a line number followed by a colon in the program. The numbering of lines should begin at number 1. BE SURE THERE ARE NO EXTRA SPACE BETWEEN THE LINES. problem 2.txt file contents: Python language is incredibly easy to use and learn for new beginners and newcomers. The python language is one of the most accessible programming languages available because it has simplified syntax and not complicated, which gives more emphasis on natural language. Due to its ease of learning and usage, python codes can be easily written and executed much faster than other programming languages. Sample output: Answer Enter a file name: Problem 2.txt line 1 Python language is incredibly easy to use and learn line 2 for new beginners and newcomers. The python language line 3 is one of the most accessible programming languages line 4 available because it has…arrow_forwardPYTHON PROGRAMMING ONLY PLEASE (PLEASE INCLUDE INPUT VALIDATIONS IF NECESSARY) Write a program that writes a series of random numbers to a file. Each random numbershould be in the range of 1 through 500. The application should let the user specify howmany random numbers the file will holdarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education