Question
Python. Read numbers from file. Objectives: Practice basic file input and list processing. Write a function to read out numbers stored in a text file.
Python. Read numbers from file.
Objectives:
Practice basic file input and list processing.
Write a function to read out numbers stored in a text file. The file contains only one line that stores multiple numbers. Each number is separated by one or more commas. The first and the second numbers are separated by one comma. The second and the third numbers are separated by two commas. The third and the fourth numbers are separated by three commas. And so on. No space is allowed before or after any comma. There is no comma after the last number; in other words, the line will not end with a comma. For the following example, eight numbers are stored in that line.
51,2,,2,,,49,,,,15,,,,,2,,,,,,1,,,,,,,14
The function should be named decipher and be able to accept a string, representing a file name, as argument. It should be able to read all numbers stored in the designated file, and return their average.
A sample file, named H11_Decipher_Sample.txt, is provided for your unit testing. If your implementation is correct, decipher("H11_Decipher_Sample.txt") should return 17.0, because the average of the numbers stored in the provided sample file H11_Decipher_Sample.txt is 17.0. Please do unit testing with different text file formats on both Apple and Windows platforms to make sure your program can correctly handle their incompatibilities, if any.
Please do unit testing with different text file formats on both Apple and Windows platforms to make sure your program can correctly handle their incompatibilities, if any.
Your decipher function should be able to take any file name as an argument and read all numbers stored in that designated file.
After function design, continue to write code to interact with users for reading and processing numbers read from a file by using your defined decipher function. Your code shall prompt for a file name and then display a message to report the average of all numbers stored in the designated file.
Function specifications:
Function name o decipher
Input parameter o a string that is a file name
return value o a number that is the average of all numbers stored in the designated file
User interface specifications:
Input o The program prompts for a file name
Output
o Display a message to report the average of all numbers stored in the designated file
T-Mobile 13:29 KH11 H11 110 Decipher.pdf objectives: Practice basic fle input and list processing. Write a function to read out numbers stored in a teat file. The file contains only one line that stores multiple numbers. Each number is separated by one or more commas. The fiest and the second numbers are separated by one comma. The second and the third numbers are separated by to commat The thed and the fourth numbers are sepawrated by three commas. And so on No space is alowed before or after any comma. There is no comma after the Last number; in other wordhs, the line will not end with a comma. For the following example, eight numbers are stored in that ine The function should be named decipher and be able to accept a string, representing a file name, as argument. It should be able to read all numbers stored in the designated file, and returm thelr average A sample file, named H11-Decipher-Sample.txt. provided for rnt testing your implementation is correct, deciphet ("111DecipherSample .txt-, should return 17.0, because the average of the numbers stored in the provided sample e 33 Deeper SampleEt I 7.0 Please do unit testing with different text file formats on both Apple and Windows platforms to make ure your program can correctly handle their incompatibilinies, If any - - Please do unit testings with different text file formats on both Apple and Windows platforms to make ure your program can comectily handle ther incompatiblites if any. Your decipher function should be able to take any file name as an argument and read all numbers stored in that designated file. After function design, continue to write code to interact with users for reading and processing numbers read from aie by uning your defined deciphes function Your code shall prompt for a file name and then display a message to report the average of al numbers stored in the designated tie. Function specification Function name o Seaipher einput parameter a string that is a fle name o a number that is the average of al nambers stoeed in the designated file User interface specifications . Input The peogram prompts for a tle name e Outpt o Display a message to rep nbers stoeed in the designated file Dashboard Calendar To Do Notifications Inbox
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started