SlideShare a Scribd company logo
+1 (315)557-6473
https://www.pythonhomeworkhelp.com/
support@pythonhomeworkhelp.com
Kolb Rd. , Tucson, Arizona,
USA
Q.1 Are each of the following True or False
a. In Python, classes do not enforce information hiding.
b. In Python, classes cannot be used as a parameter of a function.
c. Increasing the number of buckets in a hash table typically increases the amount
of time needed to locate a value in the table.
d. “Normal distribution” and “Gaussian distribution” are different names for the
same thing.
e. “Standard deviation” and “coefficient of variation” are different names for the
same thing.
Solution:
a. True
b. False
c. False
d. True
e. False
Q.2 Consider the following code:
import random
tots = [0.00]*3
maxVals = [0.0]*3
mean = 100.0
stdDevs = [0.0, 20.0, 40.0]
for i in range(1000):
for j in range(len(tots)):
next = random.gauss(mean, stdDevs[j])
tots[j] += next
if next > maxVals[j]:
maxVals[j] = next
What are the expected values of each element of tots at the end of the code?
Solution:
100,000 100,000 1000,000
Q.3 Is each of the following True or False
1. One would expect maxVals[0] to be less than maxVals[1].
2. One would expect maxVals[1] to be less than maxVals[2].
3. If the code were run twice, the value of tots[0] would be the same each time.
Solution:
1. True
2. True
3. True
Q.4 What does the following code print?
class Shape(object):
def________eq__________(s1, s2):
return s1.area() == s2.area()
def________lt ___________(s1, s2):
return s1.circum() < s2.circum()
class Rectangle(Shape):
def__init__(self, h, w):
self.height = float(h)
self.width = float(w)
def circum(self):
return 2*(self.height + self.width)
def str (self):
return 'Rectangle with area ' + str(self.height*self.width)
class Square(Rectangle):
def____init____(self, s):
Rectangle.__init__(self, s, s)
def____str____(self):
return 'Square with side ' + str(self.height)
class Circle(Shape):
def__init__(self, radius):
self.radius = float(radius)
def circum(self):
return 3.14159*(2*self.radius)
def__lt__(self, other):
return self.radius < other.radius
def__str__(self):
return 'Circle with diameter ' + str(2.0*self.radius)
def reorder(L):
for e in L:
if e < L[0]:
L[0] = e
L = [Square(6), Rectangle(2, 3), Circle(1)]
try:
reorder(L)
for e in L:
print e
except:
for e in L:
print e
Solution:
Square with side 5.0
Rectangle with area 6.0
Circle with radius 2.0
Square with side 6.0
Rectangle with area 6.0
Circle with radius 1.0
Q.5 Write a function that uses a Monte Carlo simulation to find the probability of a
run of at least 4 consecutive heads out of ten flips of a fair coin, and then returns
that probability. Assume that 10,000 trials are sufficient to provide an accurate
answer. You may invoke the function:
def simThrows(numFlips):
"""Simulates a sequence of numFlips coin flips, and returns True if the sequence
contains a run of at least four consecutive heads and False otherwise.""“
Solution:
def runSim(numTrials, numThrows):
numSuccess = 0.0
Python Homework Help
for t in range(numTrials):
if simThrows(numThrows):
numSuccess += 1.0
return numSuccess/numTrials
def sim():
return runSim(100000, 4)
Q.6 If pylab.polyfit is used to fit an nth degree and an (n+1)th degree polynomial
to the same data, is one guaranteed to provide a least squares fit that is at least as
good as the other? If so, which and why? If not, why not?
Solution:
Yes. The (n+1)th degree fit will be at least as tight, because it always possible to set
unnecessary coefficients to 0.

More Related Content

PPTX
Perfect Python Homework Help
PPT
03 boolean algebra
PPT
0453545452552155255665-Math-Functions.ppt
PPTX
Using-Python-Libraries.9485146.powerpoint.pptx
PDF
The Ring programming language version 1.3 book - Part 16 of 88
PPTX
Python Workshop - Learn Python the Hard Way
PDF
Python Cheat Sheet
PDF
The Ring programming language version 1.5.3 book - Part 36 of 184
Perfect Python Homework Help
03 boolean algebra
0453545452552155255665-Math-Functions.ppt
Using-Python-Libraries.9485146.powerpoint.pptx
The Ring programming language version 1.3 book - Part 16 of 88
Python Workshop - Learn Python the Hard Way
Python Cheat Sheet
The Ring programming language version 1.5.3 book - Part 36 of 184

Similar to Introduction to Python Programming.pptx (20)

PPTX
MyStataLab Assignment Help
PPTX
Python programming workshop
PDF
Survey Demo
DOCX
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
PDF
Pybelsberg — Constraint-based Programming in Python
PPT
haskell5.ppt is a marketing document lol
PDF
The Ring programming language version 1.3 book - Part 27 of 88
PDF
Introduction to Machine Learning
PPTX
Python Tidbits
PPT
python language programming presentation
PDF
Astronomical data analysis by python.pdf
PDF
wzhu_paper
PDF
Built-in Classes in JAVA
PPT
R for Statistical Computing
DOCX
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
PDF
1- Create a class called Point that has two instance variables, defi.pdf
PDF
Built in classes in java
PPTX
130717666736980000
PDF
MyStataLab Assignment Help
Python programming workshop
Survey Demo
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
Pybelsberg — Constraint-based Programming in Python
haskell5.ppt is a marketing document lol
The Ring programming language version 1.3 book - Part 27 of 88
Introduction to Machine Learning
Python Tidbits
python language programming presentation
Astronomical data analysis by python.pdf
wzhu_paper
Built-in Classes in JAVA
R for Statistical Computing
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
1- Create a class called Point that has two instance variables, defi.pdf
Built in classes in java
130717666736980000

More from Python Homework Help (20)

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

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
01-Introduction-to-Information-Management.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Structure & Organelles in detailed.
PDF
RMMM.pdf make it easy to upload and study
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
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O7-L3 Supply Chain Operations - ICLT Program
PPH.pptx obstetrics and gynecology in nursing
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharma ospi slides which help in ospi learning
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Computing-Curriculum for Schools in Ghana
Supply Chain Operations Speaking Notes -ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Renaissance Architecture: A Journey from Faith to Humanism
Abdominal Access Techniques with Prof. Dr. R K Mishra
01-Introduction-to-Information-Management.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Structure & Organelles in detailed.
RMMM.pdf make it easy to upload and study
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

Introduction to Python Programming.pptx

  • 2. Q.1 Are each of the following True or False a. In Python, classes do not enforce information hiding. b. In Python, classes cannot be used as a parameter of a function. c. Increasing the number of buckets in a hash table typically increases the amount of time needed to locate a value in the table. d. “Normal distribution” and “Gaussian distribution” are different names for the same thing. e. “Standard deviation” and “coefficient of variation” are different names for the same thing. Solution: a. True b. False c. False d. True e. False
  • 3. Q.2 Consider the following code: import random tots = [0.00]*3 maxVals = [0.0]*3 mean = 100.0 stdDevs = [0.0, 20.0, 40.0] for i in range(1000): for j in range(len(tots)): next = random.gauss(mean, stdDevs[j]) tots[j] += next if next > maxVals[j]: maxVals[j] = next What are the expected values of each element of tots at the end of the code? Solution: 100,000 100,000 1000,000
  • 4. Q.3 Is each of the following True or False 1. One would expect maxVals[0] to be less than maxVals[1]. 2. One would expect maxVals[1] to be less than maxVals[2]. 3. If the code were run twice, the value of tots[0] would be the same each time. Solution: 1. True 2. True 3. True Q.4 What does the following code print? class Shape(object): def________eq__________(s1, s2): return s1.area() == s2.area() def________lt ___________(s1, s2): return s1.circum() < s2.circum()
  • 5. class Rectangle(Shape): def__init__(self, h, w): self.height = float(h) self.width = float(w) def circum(self): return 2*(self.height + self.width) def str (self): return 'Rectangle with area ' + str(self.height*self.width) class Square(Rectangle): def____init____(self, s): Rectangle.__init__(self, s, s) def____str____(self): return 'Square with side ' + str(self.height) class Circle(Shape): def__init__(self, radius): self.radius = float(radius) def circum(self): return 3.14159*(2*self.radius)
  • 6. def__lt__(self, other): return self.radius < other.radius def__str__(self): return 'Circle with diameter ' + str(2.0*self.radius) def reorder(L): for e in L: if e < L[0]: L[0] = e L = [Square(6), Rectangle(2, 3), Circle(1)] try: reorder(L) for e in L: print e except: for e in L: print e Solution:
  • 7. Square with side 5.0 Rectangle with area 6.0 Circle with radius 2.0 Square with side 6.0 Rectangle with area 6.0 Circle with radius 1.0 Q.5 Write a function that uses a Monte Carlo simulation to find the probability of a run of at least 4 consecutive heads out of ten flips of a fair coin, and then returns that probability. Assume that 10,000 trials are sufficient to provide an accurate answer. You may invoke the function: def simThrows(numFlips): """Simulates a sequence of numFlips coin flips, and returns True if the sequence contains a run of at least four consecutive heads and False otherwise.""“ Solution: def runSim(numTrials, numThrows): numSuccess = 0.0
  • 8. Python Homework Help for t in range(numTrials): if simThrows(numThrows): numSuccess += 1.0 return numSuccess/numTrials def sim(): return runSim(100000, 4) Q.6 If pylab.polyfit is used to fit an nth degree and an (n+1)th degree polynomial to the same data, is one guaranteed to provide a least squares fit that is at least as good as the other? If so, which and why? If not, why not? Solution: Yes. The (n+1)th degree fit will be at least as tight, because it always possible to set unnecessary coefficients to 0.