Question

Python programming with file handling. File.csv contains a list of numbers, one integer on each line....

Python programming with file handling. File.csv contains a list of numbers, one integer on each line. Calculate the average of every 10 lines of integers and write them into another file. For example, the first 10 lines that is line 1 to line 10 contains 61, 70, 71, 90, 81, 82, 85, 90, 61, 51 each on every line

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

SOURCE CODE

import csv
count = 0
avg = 0.0
s = 0
with open('num.csv', 'r') as csvFile:
reader = csv.reader(csvFile)
for row in reader:
   s = s + int(row[0])
   count=count+1
   if(count==10):
       avg=s/10
       print("Avg = ",avg)
       count=0
       s=0

SCREENSHOT

please give a upvote if u feel helpful.

Add a comment
Know the answer?
Add Answer to:
Python programming with file handling. File.csv contains a list of numbers, one integer on each line....
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
  • Write a program in python that reads each line in a file, reverses its lines, and...

    Write a program in python that reads each line in a file, reverses its lines, and writes them to another file. For example, if the file input.txt contain the lines: Mary had a little lamb Its fleece was white as snow And everywhere that Mary went The lamb was sure to go. and you run your Python file then output.txt contains The lamb was sure to go. And everywhere that Mary went Its fleece was white as snow Mary had...

  • The file genomic_dna.txt contains a section of genomic DNA, and the file exons.txt contains a list...

    The file genomic_dna.txt contains a section of genomic DNA, and the file exons.txt contains a list of start/stop positions of exons. Each exon is on a separate line and the start and stop positions are separated by a comma. The start and stop positions follow Python conventions; they start from zero and are inclusive at the start and exclusive at the end. Write a program that will extract the exon segments, concatenate them, and write them to a new file....

  • In Python In this programming assignment, you will do multiple programming exercises, and eventually develop a...

    In Python In this programming assignment, you will do multiple programming exercises, and eventually develop a Python application that can calculate student course grades. (6 points) Write a program called p2-1.py to: (1) create a list and add integer numbers from 1 to 100 to the list; (2) calculate the average value of all numbers in the list; and (3) print the result (screenshots). (8 points) Write a program called p2-2.py to: (1) allow a user to define how many...

  • Python 3.7 Students Grade This project will have you using error handling and file handling to...

    Python 3.7 Students Grade This project will have you using error handling and file handling to display mid semester report with percentage of student work and their grade. The ‘Students.csv’ file contains students name, exam1 score, exam 2 score, assignment 1 and assignment 2 scores as well. All tasks are out of 100 each. The ‘Students’ are .csv, you may find using the csv module easier to use. However, you can always read in a line and use. split. Requirements...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • Python Basic Lists, File IO, Exception Handling 1. Call createTable() to: Read in the data from...

    Python Basic Lists, File IO, Exception Handling 1. Call createTable() to: Read in the data from each of the input files (in order from scores1.txt to scores5.txt) and store the data in table. The table is a list of lists, where the scores of each input file is a column of data of the table. By the end of the function, the table should have 5 columns of numbers, each column is from one input file. Here is the first...

  • Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array....

    Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...

  • C Programming Files.. A file has lines of text and on each there are 3 integers....

    C Programming Files.. A file has lines of text and on each there are 3 integers. How to extract each of them from all lines and store in a linked list?

  • Given a list of integers, return a list where each integer is added to 1 and...

    Given a list of integers, return a list where each integer is added to 1 and the result is multiplied by 10. You must use a list comprehension math1([1, 2, 3]) → [20, 30, 40] math1([6, 8, 6, 8, 1]) → [70, 90, 70, 90, 20] math1([10]) → [110] Complete in Python code the starter code is listed bellow def math1(lst):    return lst print(math1([1, 2, 3])) # [20, 30, 40] print(math1([6, 8, 6, 8, 1])) # [70, 90, 70,...

  • The file ‘classes.txt’ contains an unknown number of lines. Each line contains two words. The first...

    The file ‘classes.txt’ contains an unknown number of lines. Each line contains two words. The first word is the course number (‘CS021’, for example) and the second word is the instructor’s last name (Eddy). There are no duplicate courses in the file. On the other hand, an instructor may teach more than one course. Write a code segment that opens the file, loads the key/value pairs into a dictionary and then closes the file. No documentation or exception handling is...

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