SlideShare a Scribd company logo
For any help regarding Python Homework Help
visit : - https://www.pythonhomeworkhelp.com/,
Email :- support@pythonhomeworkhelp.com or
call us at :- +1 678 648 4277
1. OOP
The following definitions have been entered into a Python shell:
class Account:
chargeRate = 0.01
def __init__(self, start):
self.value = start
def debit(self, amount):
debitAmt = min(amount, self.value)
self.value = self.value - debitAmt
return debitAmt
def deposit(self, amount):
self.value += amount
def fee(self, baseAmt):
self.debit(baseAmt * self.chargeRate)
def withdraw(self, amount):
if self.value >= 10000.0:
self.fee(amount/2.0)
else:
self.fee(amount)
return self.debit(amount)
class Checking(Account):
chargeRate = 0.05
def deposit(self, amount):
if self.value <= 1:
Account.deposit(self, (1-self.chargeRate) *
amount) else:
Account.deposit(self, amount)
Assume that the following expressions have been evaluated:
Eric = Checking(4000.0)
Ellen = Account(4000.0)
Write the values of the following expressions. Write None when there is no value; write
Error when an error results and explain briefly why it’s an error. Assume that these
expressions are evaluated one after another (all of the left column first, then right column).
Eric.withdraw(3000.0)
3000.0
Ellen.withdraw(3000.0)
3000.0
Eric.value
850.0
Ellen.value
970.0
Eric.withdraw(1000.0)
800.0
Ellen.withdraw(1000.0)
960.0
Eric.value
0
Eric.deposit(5000.0)
None
Eric.value
4750.0
Ellen.value
0.0
Ellen.deposit(5000.0)
None
Ellen.value
5000.0
2 So who kicks b***
Here are some class definitions, meant to represent a league of football teams.
class Team:
def __init__(self, name, wins, losses, pointsFor, pointsAgainst):
self.name = name
self.wins = wins self.losses = losses
self.pointsFor = pointsFor
self.pointsAgainst = pointsAgainst
class League:
def __init__(self):
self.teams = {}
def addTeam(self, team):
self.teams[team.name] = team
def updateGame(self, teamName, ptsFor, ptsAgin):
# to be filled in
def computeStat(self, proc, filt):
return [proc(team) for team in self.teams.values() if filt(team)]
Imagine instantiating these classes by:
Pats = Team(’Pats’, 5, 1, 150, 100)
Ravens = Team(’Ravens’, 4, 2, 80, 30)
Colts = Team(’Colts’, 1, 4, 100, 200)
NFL = League()
NFL.addTeam(Pats)
NFL.addTeam(Ravens)
NFL.addTeam(Colts)
We would like to be able to update our information by adding in new game data. For
example, if the Pats beat the Colts, by a score of 30 to 15, the record for the Pats should
include another win, and an updated record of points for and points against; similarly
for the Colts. We would do this by calling
NFL.updateGame(’Pats’, 30, 15)
NFL.updateGame(’Colts, 15, 30)
Write a Python procedure that will complete the definition of updateGame. You may
assume that all teams exist in the instance of the league, and that there are no ties, only
wins and losses. Please make sure that the indentation of your written solution is clear.
def updateGame(self, teamName, ptsFor, ptsAgin):
team = self.teams[teamName]
if ptsFor > ptsAgin:
team.wins += 1
else:
team.losses += 1
team.pointsFor += ptsFor
team.pointsAgainst += ptsAgin
Assume that the NFL has been defined as above, but with more teams. Write an
expression using computeStat, to be evaluated by the Python interpreter, that will return
a list of wins for all teams in the NFL. (It is okay to define and use helper functions.)
For the example instance defined above, your expression should return the list:
[5, 4, 1]
NFL.computeStat(lambda y: y.wins, lambda x: True)
Write an expression using computeStat, to be evaluated by the Python interpreter, that
will return a list of the losses for the Pats and the Colts, where each entry includes the
name of the team. (It is okay to define and use helper functions.) For the example
instance defined above, your expression should return the list:
[[’Pats’, 1], [’Colts’, 4]]
NFL.computeStat(lambda y: [y.name, y.losses],
lambda x: x.name == ’Pats’ or x.name == ’Colts’)
3 Will it or won’t it?
For each difference equation below, say whether, for a unit sample input signal:
• the output of the system it describes will diverge or not as n approaches infinity,
assuming that x[n], y[n] = 0 for n < 0,
• the output of the system it describes (a) will always be positive, (b) will alternate
between positive and negative, or (c) will have a different pattern of oscillation
Part 1:
5y[n] + 2y[n − 1] = x[n − 2]
diverge? Yes or No No
Why? root’s magnitude less than 1
positive/alternate/oscillate Alternate
Why? root’s sign is negative
Part 2:
y[n] = −2y[n − 1] − 5y[n − 2] + x[n − 1]
diverge? Yes or No Yes
Why? largest root’s magnitude greater than 1
positive/alternate/oscillate Oscillates
Why?
pole is complex
4 Grow, baby, grow
You and your colleague in the Biology Department are growing cells. In each time period,
every cell in the bioreactor divides to yield itself and one new daughter cell. However,
due to aging, half of the cells die after reproducing (don’t worry about the details of how
accurately this models real cell division). We can describe this system with the following
difference equation. We let Po denote the number of cells at each time step.
Then
Po[n] = 2Po[n − 1] − 0.5Po[n − 2]
Suppose that Po[0] = 10 and Po[n] = 0 if n < 0. What are the first few values for the
number of cells (note that while not physically realistic, our model might provide
fractional answers)?
Po[0] = 10
Po[1] = 20
Po[2] = 35
Po[3] = 60
Your goal is to create a constant population of cells, that is, to keep Po constant at some
desired level Pd. You are to design a proportional controller that can add or remove cells
as a function of the difference between the actual and desired number of cells. Assume
that any additions or deletions at time n are based on the measured number of cells at
time n−1. Denote the number of cells added or removed at each step Pinp. Derive the
difference equations that govern this closed loop system.
Po[n] = 2Po[n − 1] − .5Po[n − 2] + Pinp[n]
Pinp[n] = k(Pd[n] − Po[n − 1])
Draw a block diagram that represents this system, using delays, adders/subtractors and gains
What is the system function that characterizes Use k to denote the gain in your system.
5. Predicting Growth
The following Python classes differ only in the boxed regions.
class GrowthA (SM):
startState = (0,0)
def getNextValues(self,state,input):
(s0,s1) = state
output = input + s0 + 2*s1
newState = (s1,output)
return (newState,output)
class GrowthB (SM):
startState = (0,0)
def getNextValues(self,state,input):
(s0,s1) = state
output = input + 2*s0 + s1
newState = (s1,output)
return (newState,output)
class GrowthC (SM):
startState = (0,0)
def getNextValues(self,state,input):
(s0,s1) = state
output = input + s0 + 2*s1
newState = (s1,input)
return (newState,output)
class GrowthD (SM):
startState = (0,0)
def getNextValues(self,state,input):
(s0,s1) = state
output = input + 2*s0 + s1
newState = (s1,input)
return (newState,output)
Part a. Determine which (if any) of GrowthA, GrowthB, GrowthC, and GrowthD
generate state machines whose output y[n] at time n is given by
y[n] = x[n] + x[n − 1] + 2x[n − 2]
for times n > 0, when the input x[n] = 0 for n < 0.
Circle all of the classes that satify this relation, or circle none if none satisfy it.
GrowthA GrowthB GrowthC G rowthD none
GrowthD
Part b. Determine which (if any) of GrowthA, GrowthB, GrowthC, and GrowthD
generate state
Circle all of the classes that satify this relation, or circle none if none satisfy it.
GrowthA GrowthB GrowthC GrowthD none
GrowthB
Part c. Let HA, HB, HC, and HD represent the system functions associated with the state
machines generated by GrowthA, GrowthB, GrowthC, and GrowthD, respectively. Fill in
the following Part Midterm 1 Solutions — Fall 10 11 b. Determine which (if any) of
GrowthA, GrowthB, GrowthC, and GrowthD generate state machines whose input-output
relation can be expressed as the following block diagram. Delay Delay 1 2 X Y + Circle
all of the classes that satify this relation, or circle none if none satisfy it. table to indicate
the number and locations of the poles of HA, HB, HC, and HD. Pole locations can be
listed in any order. Leave unnecessary entries blank.
2, 1 + root(2), 1 - root(2)
2, 2, -1
0
0
6 I need a caffeine jolt
Taking exams is hard work, and it would be nice if there were a caffeine dispenser
next to every student’s desk. You are to create a state machine that dispenses caffeine
jolts (unfortunately these are expensive, and cost 3 dollars each!). This machine
accepts dollar bills in different denominations, but does not make change. Hence, your
machine should have the following behavior:
• The inputs to the machine are positive integers (representing different denominations
of dollars);
• If the input plus the current amount of money deposited in the machine is greater than
3, the machine outputs the current input;
• If the input plus the current amount of money deposited in the machine is exactly 3,
the machine outputs a jolt and resets its internal state;
• If the input plus the current amount of money deposited in the machine is less than 3,
the machine adjusts its state, outputs None and waits for the next input.
Here are some examples:
>>>v = Vending()
>>>v.transduce([1,1,1])
[None, None, ’jolt’]
>>>v.transduce([1,2])
[None, ’jolt’]
>>>v.transduce([5,1,4,2])
[5, None, 4, ’jolt’]
Feel free to change the startState if it simplifies your solution. Here is an outline of our
state machine:
class Vending(sm.SM):
startState = None
def getNextValues(self, state, inp):
Complete the definition of getNextValues
class Vending(sm.SM):
startState = 0 # Note the choice of startState
def getNextValues(self, state, inp):
if state + inp > 3:
return (state, inp)
elif state + inp == 3:
return (0, ’jolt’)
else:
return (state + inp, None)

More Related Content

What's hot

Machnical Engineering Assignment Help
Machnical Engineering Assignment HelpMachnical Engineering Assignment Help
Machnical Engineering Assignment Help
Matlab Assignment Experts
 
E10
E10E10
E10
lksoo
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
Matlab Assignment Experts
 
Understanding Lemon Generated Parser
Understanding Lemon Generated ParserUnderstanding Lemon Generated Parser
Understanding Lemon Generated Parser
vivekanandan r
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
Matlab Assignment Experts
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
Solution of matlab chapter 4
Solution of matlab chapter 4Solution of matlab chapter 4
Solution of matlab chapter 4
AhsanIrshad8
 
CIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comCIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.com
claric130
 
Mechanical Engineering Assignment Help
Mechanical Engineering Assignment HelpMechanical Engineering Assignment Help
Mechanical Engineering Assignment Help
Matlab Assignment Experts
 
Killing The Unit test talk
Killing The Unit test talkKilling The Unit test talk
Killing The Unit test talk
dor sever
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about laziness
Johan Tibell
 
Programada chapter 4
Programada chapter 4Programada chapter 4
Programada chapter 4
abdallaisse
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
vikram mahendra
 
M|18 User Defined Functions
M|18 User Defined FunctionsM|18 User Defined Functions
M|18 User Defined Functions
MariaDB plc
 
Electrical Engineering Exam Help
Electrical Engineering Exam HelpElectrical Engineering Exam Help
Electrical Engineering Exam Help
Live Exam Helper
 
Lec4
Lec4Lec4
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
ARVIND PANDE
 
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
Philip Schwarz
 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }
John De Goes
 

What's hot (20)

Machnical Engineering Assignment Help
Machnical Engineering Assignment HelpMachnical Engineering Assignment Help
Machnical Engineering Assignment Help
 
E10
E10E10
E10
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Understanding Lemon Generated Parser
Understanding Lemon Generated ParserUnderstanding Lemon Generated Parser
Understanding Lemon Generated Parser
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Solution of matlab chapter 4
Solution of matlab chapter 4Solution of matlab chapter 4
Solution of matlab chapter 4
 
CIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comCIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.com
 
Mechanical Engineering Assignment Help
Mechanical Engineering Assignment HelpMechanical Engineering Assignment Help
Mechanical Engineering Assignment Help
 
Killing The Unit test talk
Killing The Unit test talkKilling The Unit test talk
Killing The Unit test talk
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about laziness
 
Programada chapter 4
Programada chapter 4Programada chapter 4
Programada chapter 4
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
M|18 User Defined Functions
M|18 User Defined FunctionsM|18 User Defined Functions
M|18 User Defined Functions
 
Electrical Engineering Exam Help
Electrical Engineering Exam HelpElectrical Engineering Exam Help
Electrical Engineering Exam Help
 
Lec4
Lec4Lec4
Lec4
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
 
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }
 

Similar to Python Homework Help

Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
Python Homework Help
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
Johan Tibell
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdf
MILANOP1
 
Side Notes on Practical Natural Language Processing: Bootstrap Test
Side Notes on Practical Natural Language Processing: Bootstrap TestSide Notes on Practical Natural Language Processing: Bootstrap Test
Side Notes on Practical Natural Language Processing: Bootstrap Test
HarithaGangavarapu
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Rakotoarison Louis Frederick
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
Programming Homework Help
 
Python Programming Homework Help.pptx
Python Programming Homework Help.pptxPython Programming Homework Help.pptx
Python Programming Homework Help.pptx
Python Homework Help
 
Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
Matlab Assignment Experts
 
Operators
OperatorsOperators
Operators
VijayaLakshmi506
 
NPTEL QUIZ.docx
NPTEL QUIZ.docxNPTEL QUIZ.docx
NPTEL QUIZ.docx
GEETHAR59
 
Dax queries.pdf
Dax queries.pdfDax queries.pdf
Dax queries.pdf
ntrnbk
 
Pre-Calculus Midterm Exam 1 Score ______ ____.docx
Pre-Calculus Midterm Exam  1  Score ______  ____.docxPre-Calculus Midterm Exam  1  Score ______  ____.docx
Pre-Calculus Midterm Exam 1 Score ______ ____.docx
ChantellPantoja184
 
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxerror 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
SALU18
 
Digital electronics k map comparators and their function
Digital electronics k map comparators and their functionDigital electronics k map comparators and their function
Digital electronics k map comparators and their function
kumarankit06875
 
Nalinee java
Nalinee javaNalinee java
Nalinee java
Nalinee Choudhary
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
Sandeep Jindal
 
python_p4_v2.pdf
python_p4_v2.pdfpython_p4_v2.pdf
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
Karwan Mustafa Kareem
 
Astronomical data analysis by python.pdf
Astronomical data analysis by python.pdfAstronomical data analysis by python.pdf
Astronomical data analysis by python.pdf
ZainRahim3
 

Similar to Python Homework Help (20)

Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdf
 
Side Notes on Practical Natural Language Processing: Bootstrap Test
Side Notes on Practical Natural Language Processing: Bootstrap TestSide Notes on Practical Natural Language Processing: Bootstrap Test
Side Notes on Practical Natural Language Processing: Bootstrap Test
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Python Programming Homework Help.pptx
Python Programming Homework Help.pptxPython Programming Homework Help.pptx
Python Programming Homework Help.pptx
 
Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
 
Operators
OperatorsOperators
Operators
 
NPTEL QUIZ.docx
NPTEL QUIZ.docxNPTEL QUIZ.docx
NPTEL QUIZ.docx
 
Dax queries.pdf
Dax queries.pdfDax queries.pdf
Dax queries.pdf
 
Pre-Calculus Midterm Exam 1 Score ______ ____.docx
Pre-Calculus Midterm Exam  1  Score ______  ____.docxPre-Calculus Midterm Exam  1  Score ______  ____.docx
Pre-Calculus Midterm Exam 1 Score ______ ____.docx
 
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxerror 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
 
Digital electronics k map comparators and their function
Digital electronics k map comparators and their functionDigital electronics k map comparators and their function
Digital electronics k map comparators and their function
 
Nalinee java
Nalinee javaNalinee java
Nalinee java
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
 
python_p4_v2.pdf
python_p4_v2.pdfpython_p4_v2.pdf
python_p4_v2.pdf
 
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
 
Astronomical data analysis by python.pdf
Astronomical data analysis by python.pdfAstronomical data analysis by python.pdf
Astronomical data analysis by python.pdf
 

More from Python Homework Help

Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Complete my Python Homework
Complete my Python HomeworkComplete my Python Homework
Complete my Python Homework
Python Homework Help
 
Introduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptxIntroduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptx
Python Homework Help
 
Basic Python Programming.pptx
Basic Python Programming.pptxBasic Python Programming.pptx
Basic Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
Python Homework Help
 
Perfect Python Homework Help
Perfect Python Homework HelpPerfect Python Homework Help
Perfect Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Programming Homework Help
Python Programming Homework HelpPython Programming Homework Help
Python Programming Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 

More from Python Homework Help (20)

Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Complete my Python Homework
Complete my Python HomeworkComplete my Python Homework
Complete my Python Homework
 
Introduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptxIntroduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptx
 
Basic Python Programming.pptx
Basic Python Programming.pptxBasic Python Programming.pptx
Basic Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
 
Perfect Python Homework Help
Perfect Python Homework HelpPerfect Python Homework Help
Perfect Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Programming Homework Help
Python Programming Homework HelpPython Programming Homework Help
Python Programming Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 

Recently uploaded

Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 

Recently uploaded (20)

Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 

Python Homework Help

  • 1. For any help regarding Python Homework Help visit : - https://www.pythonhomeworkhelp.com/, Email :- support@pythonhomeworkhelp.com or call us at :- +1 678 648 4277
  • 2. 1. OOP The following definitions have been entered into a Python shell: class Account: chargeRate = 0.01 def __init__(self, start): self.value = start def debit(self, amount): debitAmt = min(amount, self.value) self.value = self.value - debitAmt return debitAmt def deposit(self, amount): self.value += amount def fee(self, baseAmt): self.debit(baseAmt * self.chargeRate) def withdraw(self, amount): if self.value >= 10000.0: self.fee(amount/2.0) else: self.fee(amount) return self.debit(amount)
  • 3. class Checking(Account): chargeRate = 0.05 def deposit(self, amount): if self.value <= 1: Account.deposit(self, (1-self.chargeRate) * amount) else: Account.deposit(self, amount) Assume that the following expressions have been evaluated: Eric = Checking(4000.0) Ellen = Account(4000.0) Write the values of the following expressions. Write None when there is no value; write Error when an error results and explain briefly why it’s an error. Assume that these expressions are evaluated one after another (all of the left column first, then right column). Eric.withdraw(3000.0) 3000.0 Ellen.withdraw(3000.0) 3000.0
  • 5. 2 So who kicks b*** Here are some class definitions, meant to represent a league of football teams. class Team: def __init__(self, name, wins, losses, pointsFor, pointsAgainst): self.name = name self.wins = wins self.losses = losses self.pointsFor = pointsFor self.pointsAgainst = pointsAgainst class League: def __init__(self): self.teams = {} def addTeam(self, team): self.teams[team.name] = team def updateGame(self, teamName, ptsFor, ptsAgin): # to be filled in def computeStat(self, proc, filt): return [proc(team) for team in self.teams.values() if filt(team)] Imagine instantiating these classes by:
  • 6. Pats = Team(’Pats’, 5, 1, 150, 100) Ravens = Team(’Ravens’, 4, 2, 80, 30) Colts = Team(’Colts’, 1, 4, 100, 200) NFL = League() NFL.addTeam(Pats) NFL.addTeam(Ravens) NFL.addTeam(Colts) We would like to be able to update our information by adding in new game data. For example, if the Pats beat the Colts, by a score of 30 to 15, the record for the Pats should include another win, and an updated record of points for and points against; similarly for the Colts. We would do this by calling NFL.updateGame(’Pats’, 30, 15) NFL.updateGame(’Colts, 15, 30) Write a Python procedure that will complete the definition of updateGame. You may assume that all teams exist in the instance of the league, and that there are no ties, only wins and losses. Please make sure that the indentation of your written solution is clear.
  • 7. def updateGame(self, teamName, ptsFor, ptsAgin): team = self.teams[teamName] if ptsFor > ptsAgin: team.wins += 1 else: team.losses += 1 team.pointsFor += ptsFor team.pointsAgainst += ptsAgin Assume that the NFL has been defined as above, but with more teams. Write an expression using computeStat, to be evaluated by the Python interpreter, that will return a list of wins for all teams in the NFL. (It is okay to define and use helper functions.) For the example instance defined above, your expression should return the list: [5, 4, 1] NFL.computeStat(lambda y: y.wins, lambda x: True)
  • 8. Write an expression using computeStat, to be evaluated by the Python interpreter, that will return a list of the losses for the Pats and the Colts, where each entry includes the name of the team. (It is okay to define and use helper functions.) For the example instance defined above, your expression should return the list: [[’Pats’, 1], [’Colts’, 4]] NFL.computeStat(lambda y: [y.name, y.losses], lambda x: x.name == ’Pats’ or x.name == ’Colts’) 3 Will it or won’t it? For each difference equation below, say whether, for a unit sample input signal: • the output of the system it describes will diverge or not as n approaches infinity, assuming that x[n], y[n] = 0 for n < 0, • the output of the system it describes (a) will always be positive, (b) will alternate between positive and negative, or (c) will have a different pattern of oscillation
  • 9. Part 1: 5y[n] + 2y[n − 1] = x[n − 2] diverge? Yes or No No Why? root’s magnitude less than 1 positive/alternate/oscillate Alternate Why? root’s sign is negative Part 2: y[n] = −2y[n − 1] − 5y[n − 2] + x[n − 1] diverge? Yes or No Yes Why? largest root’s magnitude greater than 1
  • 10. positive/alternate/oscillate Oscillates Why? pole is complex 4 Grow, baby, grow You and your colleague in the Biology Department are growing cells. In each time period, every cell in the bioreactor divides to yield itself and one new daughter cell. However, due to aging, half of the cells die after reproducing (don’t worry about the details of how accurately this models real cell division). We can describe this system with the following difference equation. We let Po denote the number of cells at each time step. Then Po[n] = 2Po[n − 1] − 0.5Po[n − 2] Suppose that Po[0] = 10 and Po[n] = 0 if n < 0. What are the first few values for the number of cells (note that while not physically realistic, our model might provide fractional answers)?
  • 11. Po[0] = 10 Po[1] = 20 Po[2] = 35 Po[3] = 60 Your goal is to create a constant population of cells, that is, to keep Po constant at some desired level Pd. You are to design a proportional controller that can add or remove cells as a function of the difference between the actual and desired number of cells. Assume that any additions or deletions at time n are based on the measured number of cells at time n−1. Denote the number of cells added or removed at each step Pinp. Derive the difference equations that govern this closed loop system. Po[n] = 2Po[n − 1] − .5Po[n − 2] + Pinp[n] Pinp[n] = k(Pd[n] − Po[n − 1])
  • 12. Draw a block diagram that represents this system, using delays, adders/subtractors and gains What is the system function that characterizes Use k to denote the gain in your system.
  • 13. 5. Predicting Growth The following Python classes differ only in the boxed regions. class GrowthA (SM): startState = (0,0) def getNextValues(self,state,input): (s0,s1) = state output = input + s0 + 2*s1 newState = (s1,output) return (newState,output) class GrowthB (SM): startState = (0,0) def getNextValues(self,state,input): (s0,s1) = state output = input + 2*s0 + s1 newState = (s1,output) return (newState,output) class GrowthC (SM): startState = (0,0) def getNextValues(self,state,input): (s0,s1) = state output = input + s0 + 2*s1 newState = (s1,input) return (newState,output) class GrowthD (SM): startState = (0,0) def getNextValues(self,state,input): (s0,s1) = state output = input + 2*s0 + s1 newState = (s1,input) return (newState,output)
  • 14. Part a. Determine which (if any) of GrowthA, GrowthB, GrowthC, and GrowthD generate state machines whose output y[n] at time n is given by y[n] = x[n] + x[n − 1] + 2x[n − 2] for times n > 0, when the input x[n] = 0 for n < 0. Circle all of the classes that satify this relation, or circle none if none satisfy it. GrowthA GrowthB GrowthC G rowthD none GrowthD Part b. Determine which (if any) of GrowthA, GrowthB, GrowthC, and GrowthD generate state
  • 15. Circle all of the classes that satify this relation, or circle none if none satisfy it. GrowthA GrowthB GrowthC GrowthD none GrowthB Part c. Let HA, HB, HC, and HD represent the system functions associated with the state machines generated by GrowthA, GrowthB, GrowthC, and GrowthD, respectively. Fill in the following Part Midterm 1 Solutions — Fall 10 11 b. Determine which (if any) of GrowthA, GrowthB, GrowthC, and GrowthD generate state machines whose input-output relation can be expressed as the following block diagram. Delay Delay 1 2 X Y + Circle all of the classes that satify this relation, or circle none if none satisfy it. table to indicate the number and locations of the poles of HA, HB, HC, and HD. Pole locations can be listed in any order. Leave unnecessary entries blank.
  • 16. 2, 1 + root(2), 1 - root(2) 2, 2, -1 0 0 6 I need a caffeine jolt Taking exams is hard work, and it would be nice if there were a caffeine dispenser next to every student’s desk. You are to create a state machine that dispenses caffeine jolts (unfortunately these are expensive, and cost 3 dollars each!). This machine accepts dollar bills in different denominations, but does not make change. Hence, your machine should have the following behavior: • The inputs to the machine are positive integers (representing different denominations of dollars); • If the input plus the current amount of money deposited in the machine is greater than 3, the machine outputs the current input; • If the input plus the current amount of money deposited in the machine is exactly 3, the machine outputs a jolt and resets its internal state; • If the input plus the current amount of money deposited in the machine is less than 3, the machine adjusts its state, outputs None and waits for the next input.
  • 17. Here are some examples: >>>v = Vending() >>>v.transduce([1,1,1]) [None, None, ’jolt’] >>>v.transduce([1,2]) [None, ’jolt’] >>>v.transduce([5,1,4,2]) [5, None, 4, ’jolt’] Feel free to change the startState if it simplifies your solution. Here is an outline of our state machine: class Vending(sm.SM): startState = None def getNextValues(self, state, inp): Complete the definition of getNextValues
  • 18. class Vending(sm.SM): startState = 0 # Note the choice of startState def getNextValues(self, state, inp): if state + inp > 3: return (state, inp) elif state + inp == 3: return (0, ’jolt’) else: return (state + inp, None)