Problem question: Consider a ferry that can carry both cars and campers across a waterway. Each trip costs the owner approximately $10. The fee for cars is $3 and the fee for campers is $9. Let X and Y be the number of cars and campers, respectively on a given trip. Suppose the probabilities for different values of X and Yare given by the following table.
x y=0 y=1 y=2
0 0.01 0.01 0.03
1 0.03 0.08 0.07
2 0.03 0.06 0.06
3 0.07 0.07 0.13
4 0.12 0.04 0.03
5 0.08 0.07 0.01
The revenue for the ferry is given by R = 3X 9Y
. Find the possible values of R and the associated probabilities.
From the question, I know there are 18 possibile combinations of cars and campers. I'm stuck on my function for determining the possible outcomes of R.
combos = []
def problem_three():
for x in range(0,5):
for y in range(0,2):
rev = (3*int(x) 9*int(y))
combos.append(rev)
return combos
revenue = problem_three()
print(revenue)
This code returns: [0, 9, 3, 12, 6, 15, 9, 18, 12, 21]
, but that doesn't doesn't have all the values I expected - what am I missing?
CodePudding user response:
range(0, n)
is the same as range(n)
and will give you 0
through n-1
, not 0
through n
!
combos = []
def problem_three():
for x in range(5 1): # fixed
for y in range(2 1): # fixed
rev = (3*int(x) 9*int(y))
combos.append(rev) # indent
return combos
revenue = problem_three()
print(revenue)
[0, 9, 18, 3, 12, 21, 6, 15, 24, 9, 18, 27, 12, 21, 30, 15, 24, 33