SlideShare a Scribd company logo
For any help regarding Python Homework Help
Visit :- https://www.pythonhomeworkhelp.com/ ,
Email :- support@pythonhomeworkhelp.com or
Call/ Text/ WhatsApp: +1(315)557-6473
Problems and Solutions:
Problem 1 – Quick exploration of member functions
We've taught you that objects encapsulate data, and they provide member functions that operate
based on that data. Some member functions change that data – in that case, they're modifiers
and the object is mutable – while others simply return new data.
The syntax for accessing member functions of objects is:
where variable points to an object in the heap.
Since the primitive types int, float and bool are NOT objects, they don't support any member
functions. So you CAN'T do 5.something() or True.something().
However, strings are objects, so they support member functions. Same with tuples, and same
with lists. What member functions do each support? Python provides a "dir" function that takes a
variable and lists the member functions that the object supports.
For any help regarding Python Homework Help
Visit :- https://www.pythonhomeworkhelp.com/ ,
Email :- support@pythonhomeworkhelp.com or
Call/ Text/ WhatsApp: +1(315)557-6473
You should get out a bunch of what looks like jumbled nonsense. But those things are actually
member functions of each object. You'll generally see two types of member functions:
__functionname__ functions are generally not meant to be explicitly called. Instead, they're
used by Python to do other things.
Å "A" comes before "B" alphabetically, so this is True
For any help regarding Python Homework Help
Visit :- https://www.pythonhomeworkhelp.com/ ,
Email :- support@pythonhomeworkhelp.com or
Call/ Text/ WhatsApp: +1(315)557-6473
We see the same result. It turns out that whenever you write object1 < object2, Python looks for
a __lt__ member function in a and calls it with b as the argument. (In actuality, there is a little
more to the story, but we won't worry about that now.)
The __functionname__ style exists because it's meant to explicitly make it clear that this
function is not meant to be called normally. It's a system function, so in general, we should never
be calling functions with names like __functionname__.
The rest of the functions are all functions that you can use! For help with any, type:
Take a quick look at some of the functions for strings, lists and tuples... we'll be needing them.
For any help regarding Python Homework Help
Visit :- https://www.pythonhomeworkhelp.com/ ,
Email :- support@pythonhomeworkhelp.com or
Call/ Text/ WhatsApp: +1(315)557-6473
Let's say there are two methods to find the "distance" of two chromosomes -- that is, how much
the two have varied through mutations. One method is to go letter by letter and count the
number of discrepancies. Another method is to sum the discrepancies of a's (e.g. chromosome x
has 5 a's, chromosome y has 7 a's), c's, g’s, and t’s.
Are the two methods the same? We don't know, let's find out.
Write a function that uses method 1. It will take two chromosomes, and go letter by letter in
each, comparing them. It then returns the total number of discrepancies it finds.
Write another function that uses method 2. It will take two chromosomes, and return the sum of
'a' discrepancies, ‘cones, and so on.
Then call each function on each of the combinations (A,B), (A,C), (A,D), (B,C), (B, D), and (C, D)
and see which methods tell you which pair of chromosomes is "furthest" (i.e. most varied) and
which pair is "closest" (i.e. least varied).
Remember to use dir()!
Important note: From this point on, we are going to stray from interactive programs that use
raw_input and go to solving complex problems instead. You should not use a raw_input function
anywhere in this program.
For any help regarding Python Homework Help
Visit :- https://www.pythonhomeworkhelp.com/ ,
Email :- support@pythonhomeworkhelp.com or
Call/ Text/ WhatsApp: +1(315)557-6473
A = "gtggcaacgtgc"
B = "gtagcagcgcgc"
C = "gcggcacagggt"
D = "gtgacaacgtgc"
def method1(c1, c2):
discreps = 0
for i in range(len(c1)):
if c1[i] != c2[i]:
discreps = discreps + 1
return discreps
def method2(c1, c2):
discreps_a = abs(c1.count('a') - c2.count('a'))
discreps_c = abs(c1.count('c') - c2.count('c'))
discreps_g = abs(c1.count('g') - c2.count('g'))
discreps_t = abs(c1.count('t') - c2.count('t'))
return discreps_a + discreps_c + discreps_g + discreps_t
For any help regarding Python Homework Help
Visit :- https://www.pythonhomeworkhelp.com/ ,
Email :- support@pythonhomeworkhelp.com or
Call/ Text/ WhatsApp: +1(315)557-6473
def compare(c1, c2, name1, name2):
print name1, "and", name2, ":"
print "Method 1 says there are", method1(c1, c2),
"differences."
print "Method 2 says there are", method2(c1, c2),
"differences."
print
compare(A, B, "A", "B")
compare(A, C, "A", "C")
compare(A, D, "A", "D")
compare(B, C, "B", "C")
compare(B, D, "B", "D")
compare(C, D, "C", "D")
For any help regarding Python Homework Help
Visit :- https://www.pythonhomeworkhelp.com/ ,
Email :- support@pythonhomeworkhelp.com or
Call/ Text/ WhatsApp: +1(315)557-6473

More Related Content

Similar to Python Homework Help (20)

Lecture-6.pdf
Lecture-6.pdf
Bhavya103897
 
Python Programming Homework Help.pptx
Python Programming Homework Help.pptx
Python Homework Help
 
Page 1 of 3 MATH233 Unit 1 Limits Individual Proje.docx
Page 1 of 3 MATH233 Unit 1 Limits Individual Proje.docx
alfred4lewis58146
 
Basic Python Programming.pptx
Basic Python Programming.pptx
Python Homework Help
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
GaneshPawar819187
 
Python tutorial
Python tutorial
Rajiv Risi
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 
Cwkaa 2010
Cwkaa 2010
Sam Neaves
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptx
AOUNHAIDER7
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdf
karthikaparthasarath
 
Course notes on Astronomical data analysis by python pdf
Course notes on Astronomical data analysis by python pdf
ZainRahim3
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
cs class 12 project computer science .docx
cs class 12 project computer science .docx
AryanSheoran1
 
Lecturevhhgghhhvffghgzchnjuyfrtujjb-13.pdf
Lecturevhhgghhhvffghgzchnjuyfrtujjb-13.pdf
Eyasu46
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
SHA1 collision analysis and resolving a problem of recursive hashing with xra...
SHA1 collision analysis and resolving a problem of recursive hashing with xra...
Diego Hernan Marciano
 
Introduction to Functional Programming
Introduction to Functional Programming
Francesco Bruni
 
Python Programming Homework Help.pptx
Python Programming Homework Help.pptx
Python Homework Help
 
Page 1 of 3 MATH233 Unit 1 Limits Individual Proje.docx
Page 1 of 3 MATH233 Unit 1 Limits Individual Proje.docx
alfred4lewis58146
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
GaneshPawar819187
 
Python tutorial
Python tutorial
Rajiv Risi
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptx
AOUNHAIDER7
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdf
karthikaparthasarath
 
Course notes on Astronomical data analysis by python pdf
Course notes on Astronomical data analysis by python pdf
ZainRahim3
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
cs class 12 project computer science .docx
cs class 12 project computer science .docx
AryanSheoran1
 
Lecturevhhgghhhvffghgzchnjuyfrtujjb-13.pdf
Lecturevhhgghhhvffghgzchnjuyfrtujjb-13.pdf
Eyasu46
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
SHA1 collision analysis and resolving a problem of recursive hashing with xra...
SHA1 collision analysis and resolving a problem of recursive hashing with xra...
Diego Hernan Marciano
 
Introduction to Functional Programming
Introduction to Functional Programming
Francesco Bruni
 

More from Python Homework Help (20)

Python Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
Python Homework Help
 
Complete my Python Homework
Complete my Python Homework
Python Homework Help
 
Introduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Python Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
Python Homework Help
 
Quality Python Homework Help
Quality Python Homework Help
Python Homework Help
 
Perfect Python Homework Help
Perfect Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
Python Homework Help
 
Quality Python Homework Help
Quality Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
Python Homework Help
 
Python Programming Homework Help
Python Programming Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
Python Homework Help
 
Introduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 

Recently uploaded (20)

ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 

Python Homework Help

  • 1. For any help regarding Python Homework Help Visit :- https://www.pythonhomeworkhelp.com/ , Email :- [email protected] or Call/ Text/ WhatsApp: +1(315)557-6473
  • 2. Problems and Solutions: Problem 1 – Quick exploration of member functions We've taught you that objects encapsulate data, and they provide member functions that operate based on that data. Some member functions change that data – in that case, they're modifiers and the object is mutable – while others simply return new data. The syntax for accessing member functions of objects is: where variable points to an object in the heap. Since the primitive types int, float and bool are NOT objects, they don't support any member functions. So you CAN'T do 5.something() or True.something(). However, strings are objects, so they support member functions. Same with tuples, and same with lists. What member functions do each support? Python provides a "dir" function that takes a variable and lists the member functions that the object supports. For any help regarding Python Homework Help Visit :- https://www.pythonhomeworkhelp.com/ , Email :- [email protected] or Call/ Text/ WhatsApp: +1(315)557-6473
  • 3. You should get out a bunch of what looks like jumbled nonsense. But those things are actually member functions of each object. You'll generally see two types of member functions: __functionname__ functions are generally not meant to be explicitly called. Instead, they're used by Python to do other things. Å "A" comes before "B" alphabetically, so this is True For any help regarding Python Homework Help Visit :- https://www.pythonhomeworkhelp.com/ , Email :- [email protected] or Call/ Text/ WhatsApp: +1(315)557-6473
  • 4. We see the same result. It turns out that whenever you write object1 < object2, Python looks for a __lt__ member function in a and calls it with b as the argument. (In actuality, there is a little more to the story, but we won't worry about that now.) The __functionname__ style exists because it's meant to explicitly make it clear that this function is not meant to be called normally. It's a system function, so in general, we should never be calling functions with names like __functionname__. The rest of the functions are all functions that you can use! For help with any, type: Take a quick look at some of the functions for strings, lists and tuples... we'll be needing them. For any help regarding Python Homework Help Visit :- https://www.pythonhomeworkhelp.com/ , Email :- [email protected] or Call/ Text/ WhatsApp: +1(315)557-6473
  • 5. Let's say there are two methods to find the "distance" of two chromosomes -- that is, how much the two have varied through mutations. One method is to go letter by letter and count the number of discrepancies. Another method is to sum the discrepancies of a's (e.g. chromosome x has 5 a's, chromosome y has 7 a's), c's, g’s, and t’s. Are the two methods the same? We don't know, let's find out. Write a function that uses method 1. It will take two chromosomes, and go letter by letter in each, comparing them. It then returns the total number of discrepancies it finds. Write another function that uses method 2. It will take two chromosomes, and return the sum of 'a' discrepancies, ‘cones, and so on. Then call each function on each of the combinations (A,B), (A,C), (A,D), (B,C), (B, D), and (C, D) and see which methods tell you which pair of chromosomes is "furthest" (i.e. most varied) and which pair is "closest" (i.e. least varied). Remember to use dir()! Important note: From this point on, we are going to stray from interactive programs that use raw_input and go to solving complex problems instead. You should not use a raw_input function anywhere in this program. For any help regarding Python Homework Help Visit :- https://www.pythonhomeworkhelp.com/ , Email :- [email protected] or Call/ Text/ WhatsApp: +1(315)557-6473
  • 6. A = "gtggcaacgtgc" B = "gtagcagcgcgc" C = "gcggcacagggt" D = "gtgacaacgtgc" def method1(c1, c2): discreps = 0 for i in range(len(c1)): if c1[i] != c2[i]: discreps = discreps + 1 return discreps def method2(c1, c2): discreps_a = abs(c1.count('a') - c2.count('a')) discreps_c = abs(c1.count('c') - c2.count('c')) discreps_g = abs(c1.count('g') - c2.count('g')) discreps_t = abs(c1.count('t') - c2.count('t')) return discreps_a + discreps_c + discreps_g + discreps_t For any help regarding Python Homework Help Visit :- https://www.pythonhomeworkhelp.com/ , Email :- [email protected] or Call/ Text/ WhatsApp: +1(315)557-6473
  • 7. def compare(c1, c2, name1, name2): print name1, "and", name2, ":" print "Method 1 says there are", method1(c1, c2), "differences." print "Method 2 says there are", method2(c1, c2), "differences." print compare(A, B, "A", "B") compare(A, C, "A", "C") compare(A, D, "A", "D") compare(B, C, "B", "C") compare(B, D, "B", "D") compare(C, D, "C", "D") For any help regarding Python Homework Help Visit :- https://www.pythonhomeworkhelp.com/ , Email :- [email protected] or Call/ Text/ WhatsApp: +1(315)557-6473