Question

Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

Write a python program and pseudocode

The Program

Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million.

Your program should read the following and display:

  • The number of numbers in the file (i.e. count them) (counter)
  • The maximum number in the file (maximum)
  • The minimum number in the file (minimum)
  • The total of all the numbers in the file (total)
  • The average of all the numbers in the file (average)

The count should be displayed as an integer (a whole number, no decimal point). The other numbers should be displayed truncated to the nearest thousandth (three digits to the right of the decimal point), with the decimal points aligned, and use the comma for the thousand separator. The count should be aligned with the other numbers even though it is an integer (see screenshot).

The file may contain up to 1,000 numbers in it. Do not use any directory name in your file name, onlyNumbers.txt.  add bigger numbers left and right of decimal point to the created numbers file.  

The file will contain only lines with numbers. There will not be a blank line at the end of the file.

Do not use arrays for this assignment. It's actually easier to write without arrays (although it takes some more thought up front).

Use the for loop to read the file. DO NOT read the files using readline(). This will save you a significant amount of time.

This whole project is 26 lines of code without comments and blank spaces.  Keep it simple!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:::

def procesFile(fileName):
try:
with open(fileName) as f:
content = f.readlines()
content = [x.strip() for x in content]
tempNum = 0
count = 0
numMax = -99999999
numMin = 99999999
total = 0
average = 0
for record in content :
tempNum = float(record)
if numMax<tempNum:
numMax=tempNum
if numMin>tempNum:
numMin=tempNum
count+=1
total +=tempNum
average = total/count
  
print("%-16s%15s"%("Count:",count))
print("%-19s%15s"%("Maximum:","{:,.2f}".format(numMax)))
print("%-19s%15s"%("Minimum:","{:,.2f}".format(numMin)))
print("%-19s%15s"%("Total:","{:,.2f}".format(total)))
print("%-19s%15s"%("Average:","{:,.2f}".format(average)))
except:
print("Error in opening file")
  
procesFile("Numbers.txt")

output:

Add a comment
Know the answer?
Add Answer to:
Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • Arrays and reading from a file USE C++ to write a program that will read a...

    Arrays and reading from a file USE C++ to write a program that will read a file containing floating point numbers, store the numbers into an array, count how many numbers were in the file, then output the numbers in reverse order. The program should only use one array and that array should not be changed after the numbers have been read. You should assume that the file does not contain more than 100 floating point numbers. The file name...

  • Starting out with python 4th edition Write program that lets the user enter in a file...

    Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....

  • Please help with this python assignment. Thank you. question 1 Write a Python program to read...

    Please help with this python assignment. Thank you. question 1 Write a Python program to read a file line by line store it into a variable. question 2 Write a Python program to read a file line by line store it into an array. question 3 Write a python program to find the longest words. question 4 Write a Python program to count the number of lines in a text file. question 5 Write a Python program to count the...

  • IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source...

    IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source code) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional...

  • . . In this programming assignment, you need to write a CH+ program that serves as...

    . . In this programming assignment, you need to write a CH+ program that serves as a very basic word processor. The program should read lines from a file, perform some transformations, and generate formatted output on the screen. For this assignment, use the following definitions: A "word" is a sequence of non-whitespace characters. An "empty line" is a line with no characters in it at all. A "blank line" is a line containing only one or more whitespace characters....

  • I need help in Python. This is a two step problem So I have the code...

    I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...

  • Using PYTHON create a program to allow the user to enter a phrase or read a...

    Using PYTHON create a program to allow the user to enter a phrase or read a file. Make your program menu-driven to allow the user to select a option to count the total words in the phrase or file. In addition, provide a menu-selection to count the number of words start with a vowel and a selection to count the number of words that start with a consonant. Include exception handlers for file not found, divide by zero, and index...

  • (1)Write a program in Python that reads an arbitrary-length file. All lines that start with semicolons...

    (1)Write a program in Python that reads an arbitrary-length file. All lines that start with semicolons (;) or pound signs (#) should be ignored. All empty lines must be ignored Lines containing a string between square brackets are sections. Within each section, lines may contain numbers or strings. For each section, calculate the lowest, highest and modal (most common) number, and print it. In each section, also count all non-whitespace characters, and print that. Example input: ; this is a...

  • Word count. A common utility on Unix/Linux systems. This program counts the number of lines, words...

    Word count. A common utility on Unix/Linux systems. This program counts the number of lines, words (strings of characters separated by blanks or new lines), and characters in a file (not including blank spaces between words). Write your own version of this program. You will need to create a text file with a number of lines/sentences. The program should accept a filename (of your text file) from the user and then print three numbers: The count of lines/sentences The count...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT