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

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
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
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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
 

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