SlideShare a Scribd company logo
Write a function called countElements that counts the number of times two elements appear in a
list. Your task is to ask the user to enter a list and two elements which they need to count in the
list. The list and each of the elements should be inputs to a function called countElements. The
function should print the count of the number of times the elements appear in the list. def
countElements(countUst, element1, element2): Example: if the inputs to the function were ("t",
"s", 7, 7, 2], "t", and 7, the function would count the instances of the letter T and the number 7
in the list, and print the number 3. There was one T and two 7's. Name your file
Lastname_Firstname.py
Solution
def countElements(list, ch1, ch2):
count = 0
for i in range(0,len(list)):
if list[i] == ch1:
count = count + 1
for i in range(0,len(list)):
if list[i] == ch2:
count = count + 1
return count;
print countElements(["t","s",7,7,2], "t", 7)
Output:
sh-4.3$ python main.py
3

More Related Content

PDF
Convert the following expressions from infix to Reverse Polish Notati.pdf
PDF
Andy and Joan are married and under 65 years of age. They have two c.pdf
PDF
Compare the methods by which the Parsees of India benefitted from th.pdf
PDF
Computer Forensics MethodologiesList them and explain each one.P.pdf
PDF
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdf
PDF
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdf
PDF
calculate the hydrogen ion concentration in mol for the following s.pdf
PDF
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf
Convert the following expressions from infix to Reverse Polish Notati.pdf
Andy and Joan are married and under 65 years of age. They have two c.pdf
Compare the methods by which the Parsees of India benefitted from th.pdf
Computer Forensics MethodologiesList them and explain each one.P.pdf
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdf
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdf
calculate the hydrogen ion concentration in mol for the following s.pdf
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf

More from feetshoemart (20)

PDF
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
PDF
wk3 reply to prof.I need help with this question below a 200 words.pdf
PDF
Write a program that prompts the user to enter a positive integer and.pdf
PDF
This is a java lab assignment. I have added the first part java re.pdf
PDF
There is no video, All you have to do is show how you reference the .pdf
PDF
The process of Imperialism and Colonialism played a role in the esta.pdf
PDF
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
PDF
What do viral genomes look like compared to those of living organism.pdf
PDF
Verify the identity Verify the identity by transforming the left-han.pdf
PDF
Using following main file and solve the taskInst.pdf
PDF
Suppose there are 14 children trying to form two teams with seven ch.pdf
PDF
11. Define a simple deformable model to detect a half-circular shape.pdf
PDF
Section I. Multiple Choice. Fill in one letter for each question. Fil.pdf
PDF
Question 5Find the accumulated value of an investment of $1500 for.pdf
PDF
Project integration management includes the processes and activities.pdf
PDF
Possible question about horizonal and vertical imbalances Both verti.pdf
PDF
Part a. facts Gibson acquired interest in Keller 112014 Various co.pdf
PDF
Need help with some fairly simple biology questions.1. What is che.pdf
PDF
Most tederal workers do not have long careers with an agency, and g.pdf
PDF
Module 04 Discussion - The Reality of HistoryIn the introductory r.pdf
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
wk3 reply to prof.I need help with this question below a 200 words.pdf
Write a program that prompts the user to enter a positive integer and.pdf
This is a java lab assignment. I have added the first part java re.pdf
There is no video, All you have to do is show how you reference the .pdf
The process of Imperialism and Colonialism played a role in the esta.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
What do viral genomes look like compared to those of living organism.pdf
Verify the identity Verify the identity by transforming the left-han.pdf
Using following main file and solve the taskInst.pdf
Suppose there are 14 children trying to form two teams with seven ch.pdf
11. Define a simple deformable model to detect a half-circular shape.pdf
Section I. Multiple Choice. Fill in one letter for each question. Fil.pdf
Question 5Find the accumulated value of an investment of $1500 for.pdf
Project integration management includes the processes and activities.pdf
Possible question about horizonal and vertical imbalances Both verti.pdf
Part a. facts Gibson acquired interest in Keller 112014 Various co.pdf
Need help with some fairly simple biology questions.1. What is che.pdf
Most tederal workers do not have long careers with an agency, and g.pdf
Module 04 Discussion - The Reality of HistoryIn the introductory r.pdf

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharma ospi slides which help in ospi learning
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Complications of Minimal Access Surgery at WLH
PPTX
master seminar digital applications in india
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Insiders guide to clinical Medicine.pdf
PPH.pptx obstetrics and gynecology in nursing
Pharma ospi slides which help in ospi learning
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Complications of Minimal Access Surgery at WLH
master seminar digital applications in india
GDM (1) (1).pptx small presentation for students
Microbial disease of the cardiovascular and lymphatic systems
Final Presentation General Medicine 03-08-2024.pptx
Computing-Curriculum for Schools in Ghana
O7-L3 Supply Chain Operations - ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Anesthesia in Laparoscopic Surgery in India
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
TR - Agricultural Crops Production NC III.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf

Write a function called countElements that counts the number of times.pdf

  • 1. Write a function called countElements that counts the number of times two elements appear in a list. Your task is to ask the user to enter a list and two elements which they need to count in the list. The list and each of the elements should be inputs to a function called countElements. The function should print the count of the number of times the elements appear in the list. def countElements(countUst, element1, element2): Example: if the inputs to the function were ("t", "s", 7, 7, 2], "t", and 7, the function would count the instances of the letter T and the number 7 in the list, and print the number 3. There was one T and two 7's. Name your file Lastname_Firstname.py Solution def countElements(list, ch1, ch2): count = 0 for i in range(0,len(list)): if list[i] == ch1: count = count + 1 for i in range(0,len(list)): if list[i] == ch2: count = count + 1 return count; print countElements(["t","s",7,7,2], "t", 7) Output: sh-4.3$ python main.py 3