Computers and Technology, 23.04.2021 16:10 Vamoppppp
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)
Answers: 2
Computers and Technology, 22.06.2019 03:20
Which of these is a benefit of social networking? oa. hiding your true identity from friendsob. avoiding talking to people in personoc. spending time with friends instead of studyingod. connecting with new people
Answers: 2
Computers and Technology, 23.06.2019 00:30
Pl i need the answer now ! which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
Computers and Technology, 23.06.2019 17:00
What does the faves button do? a. users mark a web page as a favorite b. leads other readers to favor a specific page c. readers sort and align their favicons, or favorite icons d. leads users to a message board where they can post questions
Answers: 1
Computers and Technology, 24.06.2019 07:30
Aproject involves many computing systems working together on disjointed task towards a single goal what form of computing would the project be using
Answers: 3
Counting
This third python programming assignment, PA3, is about counting. You will write two func...
Social Studies, 20.08.2019 17:50
Biology, 20.08.2019 17:50
Mathematics, 20.08.2019 17:50
English, 20.08.2019 17:50
Mathematics, 20.08.2019 17:50
History, 20.08.2019 17:50
Social Studies, 20.08.2019 17:50
Biology, 20.08.2019 17:50
Geography, 20.08.2019 17:50
History, 20.08.2019 17:50