SlideShare a Scribd company logo
1 of 1
Download to read offline
(4) (25points) File reading, calculating, and exception error handling questions. Assume a file
contains a series of integers in file numbers.txt. You can find the file (numbers.txt) in canvas. First,
copy the file into the same directory as this python program. Then, write a program that calculates
the average of all the numbers stored in the file. Finally, your program needs to handle the
exception with appropriate error messages. When everything goes well, the average of all the
numbers =4.75 Modify the program to handle the following exceptions with messages (hint: modify
your code one at a time to trigger one of the following exceptions and restore it before simulating
another error. a) IOErroer: An error occurred while trying to read the file. [Errno 2] No such file or
directoryi numbersitkt' b) ValueError: Non-numeric data found in the file could not convert string to
float: alin c) Exception: An error occurred float division by zero

More Related Content

Similar to 4 25points File reading calculating and exception erro.pdf

Assignment- C++ Write a program that reads a text file using binary mo.docx
Assignment- C++ Write a program that reads a text file using binary mo.docxAssignment- C++ Write a program that reads a text file using binary mo.docx
Assignment- C++ Write a program that reads a text file using binary mo.docx
bickerstaffinell
 
Educational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdfEducational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdf
rajeshjangid1865
 
fileop report
fileop reportfileop report
fileop report
Jason Lu
 
Finding Similar Files in Large Document Repositories
Finding Similar Files in Large Document RepositoriesFinding Similar Files in Large Document Repositories
Finding Similar Files in Large Document Repositories
feiwin
 
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdfReaction StatisticsBackgroundWhen collecting experimental data f.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
fashionbigchennai
 
Student NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docxStudent NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docx
emelyvalg9
 
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R  6.docxCopyright © 2018 Pearson Education, Inc. C H A P T E R  6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
dickonsondorris
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfQuestion 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdf
anjandavid
 
This project is the first projects you will be working on this quart.pdf
This project is the first projects you will be working on this quart.pdfThis project is the first projects you will be working on this quart.pdf
This project is the first projects you will be working on this quart.pdf
eyewaregallery
 
Hey i have attached the required file for my assignment.and addi
Hey i have attached the required file for my assignment.and addiHey i have attached the required file for my assignment.and addi
Hey i have attached the required file for my assignment.and addi
sorayan5ywschuit
 

Similar to 4 25points File reading calculating and exception erro.pdf (20)

Assignment- C++ Write a program that reads a text file using binary mo.docx
Assignment- C++ Write a program that reads a text file using binary mo.docxAssignment- C++ Write a program that reads a text file using binary mo.docx
Assignment- C++ Write a program that reads a text file using binary mo.docx
 
Online CPP Homework Help
Online CPP Homework HelpOnline CPP Homework Help
Online CPP Homework Help
 
Educational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdfEducational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdf
 
fileop report
fileop reportfileop report
fileop report
 
C- language Lecture 8
C- language Lecture 8C- language Lecture 8
C- language Lecture 8
 
Finding Similar Files in Large Document Repositories
Finding Similar Files in Large Document RepositoriesFinding Similar Files in Large Document Repositories
Finding Similar Files in Large Document Repositories
 
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdfReaction StatisticsBackgroundWhen collecting experimental data f.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
 
Student NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docxStudent NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docx
 
GE3151_PSPP_UNIT_5_Notes
GE3151_PSPP_UNIT_5_NotesGE3151_PSPP_UNIT_5_Notes
GE3151_PSPP_UNIT_5_Notes
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R  6.docxCopyright © 2018 Pearson Education, Inc. C H A P T E R  6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
 
Module2-Files.pdf
Module2-Files.pdfModule2-Files.pdf
Module2-Files.pdf
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfQuestion 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdf
 
Python-files
Python-filesPython-files
Python-files
 
Asert threat-intelligence-brief-2014-07-illuminating-etumbot-apt
Asert threat-intelligence-brief-2014-07-illuminating-etumbot-aptAsert threat-intelligence-brief-2014-07-illuminating-etumbot-apt
Asert threat-intelligence-brief-2014-07-illuminating-etumbot-apt
 
Linux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/OLinux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/O
 
This project is the first projects you will be working on this quart.pdf
This project is the first projects you will be working on this quart.pdfThis project is the first projects you will be working on this quart.pdf
This project is the first projects you will be working on this quart.pdf
 
Hey i have attached the required file for my assignment.and addi
Hey i have attached the required file for my assignment.and addiHey i have attached the required file for my assignment.and addi
Hey i have attached the required file for my assignment.and addi
 

More from VANDANASINHACONSULT

More from VANDANASINHACONSULT (20)

4 Alex Blake Chris Drew and Jordan work for a publishing.pdf
4 Alex Blake Chris Drew and Jordan work for a publishing.pdf4 Alex Blake Chris Drew and Jordan work for a publishing.pdf
4 Alex Blake Chris Drew and Jordan work for a publishing.pdf
 
4 About 20 years ago money was invested to create a forest.pdf
4 About 20 years ago money was invested to create a forest.pdf4 About 20 years ago money was invested to create a forest.pdf
4 About 20 years ago money was invested to create a forest.pdf
 
4 According to Cynthia Garcia Coll and her colleagues chil.pdf
4 According to Cynthia Garcia Coll and her colleagues chil.pdf4 According to Cynthia Garcia Coll and her colleagues chil.pdf
4 According to Cynthia Garcia Coll and her colleagues chil.pdf
 
4 A local restaurant is concerned about their ability to pr.pdf
4 A local restaurant is concerned about their ability to pr.pdf4 A local restaurant is concerned about their ability to pr.pdf
4 A local restaurant is concerned about their ability to pr.pdf
 
4 A 5yearold girl is brought to the physicians office be.pdf
4 A 5yearold girl is brought to the physicians office be.pdf4 A 5yearold girl is brought to the physicians office be.pdf
4 A 5yearold girl is brought to the physicians office be.pdf
 
3Consider the dorsal and ventral halves D and Ve of the X.pdf
3Consider the dorsal and ventral halves D and Ve of the X.pdf3Consider the dorsal and ventral halves D and Ve of the X.pdf
3Consider the dorsal and ventral halves D and Ve of the X.pdf
 
38 A 26yearold man visits his family physician complainin.pdf
38 A 26yearold man visits his family physician complainin.pdf38 A 26yearold man visits his family physician complainin.pdf
38 A 26yearold man visits his family physician complainin.pdf
 
4 4 pts Bonnie and Clyde Remember Bonnie and Clydes pris.pdf
4 4 pts Bonnie and Clyde Remember Bonnie and Clydes pris.pdf4 4 pts Bonnie and Clyde Remember Bonnie and Clydes pris.pdf
4 4 pts Bonnie and Clyde Remember Bonnie and Clydes pris.pdf
 
4 4 pts In what major sedimentary depositional environmen.pdf
4 4 pts In what major sedimentary depositional environmen.pdf4 4 pts In what major sedimentary depositional environmen.pdf
4 4 pts In what major sedimentary depositional environmen.pdf
 
4 10 pts You have mutated normal epidermal fibroblast cel.pdf
4 10 pts You have mutated normal epidermal fibroblast cel.pdf4 10 pts You have mutated normal epidermal fibroblast cel.pdf
4 10 pts You have mutated normal epidermal fibroblast cel.pdf
 
4 12 points An FA illustrating a simplified version of le.pdf
4 12 points An FA illustrating a simplified version of le.pdf4 12 points An FA illustrating a simplified version of le.pdf
4 12 points An FA illustrating a simplified version of le.pdf
 
4 20 pt Simple linear regression is considered in a data .pdf
4 20 pt Simple linear regression is considered in a data .pdf4 20 pt Simple linear regression is considered in a data .pdf
4 20 pt Simple linear regression is considered in a data .pdf
 
4 2 pts Consider the ER schema for the MOVIES database as.pdf
4 2 pts Consider the ER schema for the MOVIES database as.pdf4 2 pts Consider the ER schema for the MOVIES database as.pdf
4 2 pts Consider the ER schema for the MOVIES database as.pdf
 
4 10 Percent Ryan Enterprises forecasts the free cash flo.pdf
4 10 Percent Ryan Enterprises forecasts the free cash flo.pdf4 10 Percent Ryan Enterprises forecasts the free cash flo.pdf
4 10 Percent Ryan Enterprises forecasts the free cash flo.pdf
 
3Use Tukeys multiple comparison method to decide among whi.pdf
3Use Tukeys multiple comparison method to decide among whi.pdf3Use Tukeys multiple comparison method to decide among whi.pdf
3Use Tukeys multiple comparison method to decide among whi.pdf
 
329 In the last decade the average age of a mother at chil.pdf
329 In the last decade the average age of a mother at chil.pdf329 In the last decade the average age of a mother at chil.pdf
329 In the last decade the average age of a mother at chil.pdf
 
36 In 1812 an earthquake centered on the San Andreas fault.pdf
36 In 1812 an earthquake centered on the San Andreas fault.pdf36 In 1812 an earthquake centered on the San Andreas fault.pdf
36 In 1812 an earthquake centered on the San Andreas fault.pdf
 
36 Most of the catbon dioxide earried inthe blood is transp.pdf
36 Most of the catbon dioxide earried inthe blood is transp.pdf36 Most of the catbon dioxide earried inthe blood is transp.pdf
36 Most of the catbon dioxide earried inthe blood is transp.pdf
 
36 The kidneys maintain blood fluid volume through the neph.pdf
36 The kidneys maintain blood fluid volume through the neph.pdf36 The kidneys maintain blood fluid volume through the neph.pdf
36 The kidneys maintain blood fluid volume through the neph.pdf
 
319 Let the random variable X have the pdf fx 21x0x.pdf
319 Let the random variable X have the pdf fx 21x0x.pdf319 Let the random variable X have the pdf fx 21x0x.pdf
319 Let the random variable X have the pdf fx 21x0x.pdf
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

4 25points File reading calculating and exception erro.pdf

  • 1. (4) (25points) File reading, calculating, and exception error handling questions. Assume a file contains a series of integers in file numbers.txt. You can find the file (numbers.txt) in canvas. First, copy the file into the same directory as this python program. Then, write a program that calculates the average of all the numbers stored in the file. Finally, your program needs to handle the exception with appropriate error messages. When everything goes well, the average of all the numbers =4.75 Modify the program to handle the following exceptions with messages (hint: modify your code one at a time to trigger one of the following exceptions and restore it before simulating another error. a) IOErroer: An error occurred while trying to read the file. [Errno 2] No such file or directoryi numbersitkt' b) ValueError: Non-numeric data found in the file could not convert string to float: alin c) Exception: An error occurred float division by zero