subject

Counting This third python programming assignment, PA3, is about counting. You will write two functions partitions(n, k) that counts in how many ways n distinct elements can be grouped into k (non empty) partitions, and mkCh(a, c) that counts in how many ways amount a can be paid with coins {1,5,10,25}. Both algorithms are discussed in lecture 15: counting. Start with the skeleton code. A correct implementation of counting:
python3 counting. py 3 2
produces
n: 3 k: 2 partitions: 3
amount: 32 coins: [1, 5, 10, 25] ways: 18
counting. txt
import sys
coins = [1,5,10,25]
def partitions(n, k):
"""
pre 00
post return the number of ways k partitions
can be formed out of n distinct elements
"""
# if k==n or k==1 :
# there is only one way to form partitions
# else :
# select an element a, and
# either
# form k partitions with the rest of the elements
# and let a join one of these k groups
# or
# let a form its own partition, and
# form k-1 partitions with the rest
return 1
def mkCh(a, c):
"""
given coin set {1,5,10,25} count how many ways we can pay amount a,
c indicates which coin is considered first. c starts as the index
of the last coin value (len(coins)-1)
"""
return 1
if __name__ == "__main__":
# partititions
d = len(sys. argv)>3
n = int(sys. argv[1])
k = int(sys. argv[2])
p = partitions(n, k)
print("n:",n,"k:",k, "partitions:",p)
# make change
c = len(coins)-1
a = 10*n+k
ways = mkCh(a, c)
print("amount:", a, "coins:", coins, "ways:", ways)

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:00
What is the first step in creating a maintenance ?
Answers: 2
question
Computers and Technology, 22.06.2019 14:00
Which database model is best used for data warehouse and data mining
Answers: 3
question
Computers and Technology, 22.06.2019 16:10
When copying and pasting text, the first step is move your cursor type the text select the copy command select the paste command
Answers: 2
question
Computers and Technology, 22.06.2019 17:30
Working on this program in python 3.7: a year in the modern gregorian calendar consists of 365 days. in reality, the earth takes longer to rotate around the sun. to account for the difference in time, every 4 years, a leap year takes place. a leap year is when a year has 366 days: an extra day, february 29th. the requirements for a given year to be a leap year are: 1) the year must be divisible by 42) if the year is a century year (1700, 1800, the year must be evenly divisible by 400some example leap years are 1600, 1712, and 2016.write a program that takes in a year and determines whether that year is a leap year.ex: if the input is 1712, the output is: 1712 is a leap year. ex: if the input is 1913, the output is: 1913 is not a leap year. your program must define and call the function isleapyear(useryear). the function should return true if the input year is a leap year and false otherwise.
Answers: 1
You know the right answer?
Counting This third python programming assignment, PA3, is about counting. You will write two func...
Questions
question
History, 16.01.2020 16:31
question
History, 16.01.2020 16:31
question
Mathematics, 16.01.2020 16:31
Questions on the website: 13722361