Sum of odd integer numbers: In this problem, you are going to read a series of integer values from the file and calculate sum and average of the odd numbers only. You should create a function to complete this program as the following: # complete the following function def calculate_sum(filename):

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Nee dpythin create a function that calculates the sum and average of the odd numbers that you read from the file. 

 

(A) Python for Eve X wex Eligible Expen X
с
с
Logout
CS170 FileFun
X
MasterClass X Bb CS170 FileFun X
blackboard.truman.edu/bbcswebdav/pid-1153421-dt-content-rid-14591826_1/courses/2021404103/CS170%20FileFun.pdf
# complete the following function
def calculate_sum (filename):
try:
1/3
Sum of odd integer numbers:
In this problem, you are going to read a series of integer values from the file and calculate the
sum and average of the odd numbers only.
You should create a function to complete this program as the following:
22
7
1
9
2
100% +
except: # catch exceptions.
print("")
Syllabus of the X
infile= open(filename, "r")
# calculate the sum of the odd numbers only
# further, call the function with filename
calculate_sum("data.txt")
Sample Input (data.txt)
10
33
anaconda pyth x as Average of od X
Format your program as the above and complete the body of the function that calculates the
sum and average of the odd numbers that you read from the file. For this program, you need
to create a text file named "data.txt" and place it in the same folder as the program file.
Input for this program are from a file named data.txt. Each line of the file contains one integer
number. For example, in the following file, your program will calculate the summation of the
numbers 33, 7, 1 and 9. Hence, the summation would be 50.00 and average would be 12.50.
Sample Output
Sum of the odd numbers is: 50.00
Average is: 12.50
as Python progra X
☆
ů
+
A
•
⠀
Transcribed Image Text:(A) Python for Eve X wex Eligible Expen X с с Logout CS170 FileFun X MasterClass X Bb CS170 FileFun X blackboard.truman.edu/bbcswebdav/pid-1153421-dt-content-rid-14591826_1/courses/2021404103/CS170%20FileFun.pdf # complete the following function def calculate_sum (filename): try: 1/3 Sum of odd integer numbers: In this problem, you are going to read a series of integer values from the file and calculate the sum and average of the odd numbers only. You should create a function to complete this program as the following: 22 7 1 9 2 100% + except: # catch exceptions. print("") Syllabus of the X infile= open(filename, "r") # calculate the sum of the odd numbers only # further, call the function with filename calculate_sum("data.txt") Sample Input (data.txt) 10 33 anaconda pyth x as Average of od X Format your program as the above and complete the body of the function that calculates the sum and average of the odd numbers that you read from the file. For this program, you need to create a text file named "data.txt" and place it in the same folder as the program file. Input for this program are from a file named data.txt. Each line of the file contains one integer number. For example, in the following file, your program will calculate the summation of the numbers 33, 7, 1 and 9. Hence, the summation would be 50.00 and average would be 12.50. Sample Output Sum of the odd numbers is: 50.00 Average is: 12.50 as Python progra X ☆ ů + A • ⠀
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education