Using python, Coupon Collector is a classic statistics problem with many practic
ID: 3573012 • Letter: U
Question
Using python,
Coupon Collector is a classic statistics problem with many practical applications. The problem is to pick objects from a set of objects repeatedly and find out how many picks are needed for all the objects to be picked at least once. A variation of the problem is to pick cards from a shuffled deck of 52 cards repeatedly and find out how many picks are needed before you see one of each suit. Assume a picked card is placed back in the deck before picking another. Write a program to simulate the number of picks needed to get four cards, one from each suit and display the four cards picked (it is possible a card may be picked twice). Here is a sample run of the program: Queen of Spades 5 of Clubs Queen of Hearts 4 of Diamonds Number of picks: 12Explanation / Answer
# outline functions
def add(x, y):
"""This perform adds 2 numbers"""
come back x + y
def subtract(x, y):
"""This perform subtracts 2 numbers"""
come back x - y
def multiply(x, y):
"""This perform multiplies 2 numbers"""
come back x * y
def divide(x, y):
"""This perform divides 2 numbers"""
come back x / y
# take input from the user
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
choice = input("Enter alternative(1/2/3/4):")
num1 = int(input("Enter 1st number: "))
num2 = int(input("Enter second number: "))
if alternative == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif alternative == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif alternative == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif alternative == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.