SlideShare a Scribd company logo
1 of 1
Download to read offline
Python programming question :
Assume that a file containing a series of integers is named numbers.txt. Write
a program that calculates the average of all the numbers stored in the file.
49.6
expexted result : 349.2
Solution
numbers = []
with open("numbers.txt", "r") as ins:
for line in ins:
numbers.append(line)
sum = 0
for i in range(0, len(numbers)):
sum = sum + int(numbers[i])
average = sum/float(len(numbers))
print "Average is ", average
OUtput:
sh-4.3$ python
main.py
Average is 5.5
numbers.txt
1
2
3
4
5
6
7
8
9
10

More Related Content

More from bermanbeancolungak45

What aspects of todays information economy have influenced the imp.pdf
What aspects of todays information economy have influenced the imp.pdfWhat aspects of todays information economy have influenced the imp.pdf
What aspects of todays information economy have influenced the imp.pdfbermanbeancolungak45
 
This week, we are going to work together as a class to assist the Lon.pdf
This week, we are going to work together as a class to assist the Lon.pdfThis week, we are going to work together as a class to assist the Lon.pdf
This week, we are going to work together as a class to assist the Lon.pdfbermanbeancolungak45
 
The phylogenetic species concept looks at environmental adaptations a.pdf
The phylogenetic species concept looks at environmental adaptations a.pdfThe phylogenetic species concept looks at environmental adaptations a.pdf
The phylogenetic species concept looks at environmental adaptations a.pdfbermanbeancolungak45
 
The percentage of high school students who drink and drive was 17.5.pdf
The percentage of high school students who drink and drive was 17.5.pdfThe percentage of high school students who drink and drive was 17.5.pdf
The percentage of high school students who drink and drive was 17.5.pdfbermanbeancolungak45
 
Take a position on this statement The media represent realistic ima.pdf
Take a position on this statement The media represent realistic ima.pdfTake a position on this statement The media represent realistic ima.pdf
Take a position on this statement The media represent realistic ima.pdfbermanbeancolungak45
 
Suppose 60 different survey organizations visit eastern Tennessee to.pdf
Suppose 60 different survey organizations visit eastern Tennessee to.pdfSuppose 60 different survey organizations visit eastern Tennessee to.pdf
Suppose 60 different survey organizations visit eastern Tennessee to.pdfbermanbeancolungak45
 
Relate selected early morphological developments in the ancestors of.pdf
Relate selected early morphological developments in the ancestors of.pdfRelate selected early morphological developments in the ancestors of.pdf
Relate selected early morphological developments in the ancestors of.pdfbermanbeancolungak45
 
Question VI. In 1976, Hozumi and Tonegawa published an elegant paper.pdf
Question VI. In 1976, Hozumi and Tonegawa published an elegant paper.pdfQuestion VI. In 1976, Hozumi and Tonegawa published an elegant paper.pdf
Question VI. In 1976, Hozumi and Tonegawa published an elegant paper.pdfbermanbeancolungak45
 
question - Jurassic Park (book and movie) proposed the concept of.pdf
question - Jurassic Park (book and movie) proposed the concept of.pdfquestion - Jurassic Park (book and movie) proposed the concept of.pdf
question - Jurassic Park (book and movie) proposed the concept of.pdfbermanbeancolungak45
 
Prior to the development of anti-retroviral drugs, HIV infected pati.pdf
Prior to the development of anti-retroviral drugs, HIV infected pati.pdfPrior to the development of anti-retroviral drugs, HIV infected pati.pdf
Prior to the development of anti-retroviral drugs, HIV infected pati.pdfbermanbeancolungak45
 
Please this is my second time posting. I really need the right answe.pdf
Please this is my second time posting. I really need the right answe.pdfPlease this is my second time posting. I really need the right answe.pdf
Please this is my second time posting. I really need the right answe.pdfbermanbeancolungak45
 
Please by using Computer!Each of you were assigned a count.pdf
Please by using Computer!Each of you were assigned a count.pdfPlease by using Computer!Each of you were assigned a count.pdf
Please by using Computer!Each of you were assigned a count.pdfbermanbeancolungak45
 
ort Answer 1) Why would migration to an island by a single p.pdf
ort Answer 1) Why would migration to an island by a single p.pdfort Answer 1) Why would migration to an island by a single p.pdf
ort Answer 1) Why would migration to an island by a single p.pdfbermanbeancolungak45
 
Match the brain function with the area of the brain, (what.pdf
Match the brain function with the area of the brain, (what.pdfMatch the brain function with the area of the brain, (what.pdf
Match the brain function with the area of the brain, (what.pdfbermanbeancolungak45
 
Kyle has two friends Jeff and Shane. However, they cannot be very go.pdf
Kyle has two friends Jeff and Shane. However, they cannot be very go.pdfKyle has two friends Jeff and Shane. However, they cannot be very go.pdf
Kyle has two friends Jeff and Shane. However, they cannot be very go.pdfbermanbeancolungak45
 
In groups, start with a brainstorming session on what you know and do.pdf
In groups, start with a brainstorming session on what you know and do.pdfIn groups, start with a brainstorming session on what you know and do.pdf
In groups, start with a brainstorming session on what you know and do.pdfbermanbeancolungak45
 
How would you write this in MARIE assembly languageint count = 0;.pdf
How would you write this in MARIE assembly languageint count = 0;.pdfHow would you write this in MARIE assembly languageint count = 0;.pdf
How would you write this in MARIE assembly languageint count = 0;.pdfbermanbeancolungak45
 
I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfbermanbeancolungak45
 
How is the population on Earth protected from each radiation type A.pdf
How is the population on Earth protected from each radiation type A.pdfHow is the population on Earth protected from each radiation type A.pdf
How is the population on Earth protected from each radiation type A.pdfbermanbeancolungak45
 
Farmer Brown plans on adding fertilizer to his crop. However, hes a.pdf
Farmer Brown plans on adding fertilizer to his crop. However, hes a.pdfFarmer Brown plans on adding fertilizer to his crop. However, hes a.pdf
Farmer Brown plans on adding fertilizer to his crop. However, hes a.pdfbermanbeancolungak45
 

More from bermanbeancolungak45 (20)

What aspects of todays information economy have influenced the imp.pdf
What aspects of todays information economy have influenced the imp.pdfWhat aspects of todays information economy have influenced the imp.pdf
What aspects of todays information economy have influenced the imp.pdf
 
This week, we are going to work together as a class to assist the Lon.pdf
This week, we are going to work together as a class to assist the Lon.pdfThis week, we are going to work together as a class to assist the Lon.pdf
This week, we are going to work together as a class to assist the Lon.pdf
 
The phylogenetic species concept looks at environmental adaptations a.pdf
The phylogenetic species concept looks at environmental adaptations a.pdfThe phylogenetic species concept looks at environmental adaptations a.pdf
The phylogenetic species concept looks at environmental adaptations a.pdf
 
The percentage of high school students who drink and drive was 17.5.pdf
The percentage of high school students who drink and drive was 17.5.pdfThe percentage of high school students who drink and drive was 17.5.pdf
The percentage of high school students who drink and drive was 17.5.pdf
 
Take a position on this statement The media represent realistic ima.pdf
Take a position on this statement The media represent realistic ima.pdfTake a position on this statement The media represent realistic ima.pdf
Take a position on this statement The media represent realistic ima.pdf
 
Suppose 60 different survey organizations visit eastern Tennessee to.pdf
Suppose 60 different survey organizations visit eastern Tennessee to.pdfSuppose 60 different survey organizations visit eastern Tennessee to.pdf
Suppose 60 different survey organizations visit eastern Tennessee to.pdf
 
Relate selected early morphological developments in the ancestors of.pdf
Relate selected early morphological developments in the ancestors of.pdfRelate selected early morphological developments in the ancestors of.pdf
Relate selected early morphological developments in the ancestors of.pdf
 
Question VI. In 1976, Hozumi and Tonegawa published an elegant paper.pdf
Question VI. In 1976, Hozumi and Tonegawa published an elegant paper.pdfQuestion VI. In 1976, Hozumi and Tonegawa published an elegant paper.pdf
Question VI. In 1976, Hozumi and Tonegawa published an elegant paper.pdf
 
question - Jurassic Park (book and movie) proposed the concept of.pdf
question - Jurassic Park (book and movie) proposed the concept of.pdfquestion - Jurassic Park (book and movie) proposed the concept of.pdf
question - Jurassic Park (book and movie) proposed the concept of.pdf
 
Prior to the development of anti-retroviral drugs, HIV infected pati.pdf
Prior to the development of anti-retroviral drugs, HIV infected pati.pdfPrior to the development of anti-retroviral drugs, HIV infected pati.pdf
Prior to the development of anti-retroviral drugs, HIV infected pati.pdf
 
Please this is my second time posting. I really need the right answe.pdf
Please this is my second time posting. I really need the right answe.pdfPlease this is my second time posting. I really need the right answe.pdf
Please this is my second time posting. I really need the right answe.pdf
 
Please by using Computer!Each of you were assigned a count.pdf
Please by using Computer!Each of you were assigned a count.pdfPlease by using Computer!Each of you were assigned a count.pdf
Please by using Computer!Each of you were assigned a count.pdf
 
ort Answer 1) Why would migration to an island by a single p.pdf
ort Answer 1) Why would migration to an island by a single p.pdfort Answer 1) Why would migration to an island by a single p.pdf
ort Answer 1) Why would migration to an island by a single p.pdf
 
Match the brain function with the area of the brain, (what.pdf
Match the brain function with the area of the brain, (what.pdfMatch the brain function with the area of the brain, (what.pdf
Match the brain function with the area of the brain, (what.pdf
 
Kyle has two friends Jeff and Shane. However, they cannot be very go.pdf
Kyle has two friends Jeff and Shane. However, they cannot be very go.pdfKyle has two friends Jeff and Shane. However, they cannot be very go.pdf
Kyle has two friends Jeff and Shane. However, they cannot be very go.pdf
 
In groups, start with a brainstorming session on what you know and do.pdf
In groups, start with a brainstorming session on what you know and do.pdfIn groups, start with a brainstorming session on what you know and do.pdf
In groups, start with a brainstorming session on what you know and do.pdf
 
How would you write this in MARIE assembly languageint count = 0;.pdf
How would you write this in MARIE assembly languageint count = 0;.pdfHow would you write this in MARIE assembly languageint count = 0;.pdf
How would you write this in MARIE assembly languageint count = 0;.pdf
 
I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdf
 
How is the population on Earth protected from each radiation type A.pdf
How is the population on Earth protected from each radiation type A.pdfHow is the population on Earth protected from each radiation type A.pdf
How is the population on Earth protected from each radiation type A.pdf
 
Farmer Brown plans on adding fertilizer to his crop. However, hes a.pdf
Farmer Brown plans on adding fertilizer to his crop. However, hes a.pdfFarmer Brown plans on adding fertilizer to his crop. However, hes a.pdf
Farmer Brown plans on adding fertilizer to his crop. However, hes a.pdf
 

Recently uploaded

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.pdfPoh-Sun Goh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
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.pptxAreebaZafar22
 
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.pdfAdmir Softic
 
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 Delhikauryashika82
 
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.docxRamakrishna Reddy Bijjam
 
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 FellowsMebane Rash
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
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 . pdfQucHHunhnh
 
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.MaryamAhmad92
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
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...Poonam Aher Patil
 

Recently uploaded (20)

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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
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
 
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
 
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
 
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
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
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
 
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
 
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.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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...
 

Python programming question Assume that a file containing a serie.pdf

  • 1. Python programming question : Assume that a file containing a series of integers is named numbers.txt. Write a program that calculates the average of all the numbers stored in the file. 49.6 expexted result : 349.2 Solution numbers = [] with open("numbers.txt", "r") as ins: for line in ins: numbers.append(line) sum = 0 for i in range(0, len(numbers)): sum = sum + int(numbers[i]) average = sum/float(len(numbers)) print "Average is ", average OUtput: sh-4.3$ python main.py Average is 5.5 numbers.txt 1 2 3 4 5 6 7 8 9 10