Question

Given a list of balls = [(Red, 10), (Blue, -20), (Green, 30), (Black, 100), (Yellow, 60),...

Given a list of balls = [(Red, 10), (Blue, -20), (Green, 30), (Black, 100), (Yellow, 60), (Cyan, 40), (Brown, 80), (White, 88), (Pink, 10), ()]. Have the user pick 3 colors. Report the total value of the colors picked. The user is allowed to pick repeated colors. Input validation is not required. Write a code for this (PYTHON).

For example,

INPUT:

Pick 3 colors from (Red, Blue, Green, Black, Yellow, Cyan, Brown, White, Pink): Red, Blue, Cyan

OUTPUT:

Your Score is: 30

Homework Answers

Answer #1
balls = [("Red", 10), ("Blue", -20), ("Green", 30), ("Black", 100), ("Yellow", 60), ("Cyan", 40), ("Brown", 80), ("White", 88), ("Pink", 10), ()]
print("Pick 3 colors from (Red, Blue, Green, Black, Yellow, Cyan, Brown, White, Pink): Red, Blue, Cyan")
s = 0
for i in range(3):
    color = input()
    for j in range(len(balls)):
        if len(balls[j])==2 and color == balls[j][0]:
            s += balls[j][1]
print("Your Score is:",s)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
You have been given the following lists of Color and their specific codes: Colors = ['Red','Blue','Green','Black','Yellow',‘Orange’,‘Purple’,‘Nocolor’]...
You have been given the following lists of Color and their specific codes: Colors = ['Red','Blue','Green','Black','Yellow',‘Orange’,‘Purple’,‘Nocolor’] Codes = [97,17,19,128,66,111,231,00] 1. Using codeDict, find the score for 'Nocolor'. 2. Add a code of 333 for 'Nocolor'. 3. Create a sorted list of all the codes in codeDict. 4. Update the name for 'Nocolor' to be ‘white’ 5. White was not a part of original colors list so, just Delete it and its code from codeDict. USE PYTHON CONSOLE AND SUBMIT THE...
In an urn, there are 20 balls of four colors: red, black, yellow and blue. For...
In an urn, there are 20 balls of four colors: red, black, yellow and blue. For each color, there are 5 balls and they are numbered from 1 to 5. 1) If one ball is randomly drawn from the urn, what is the probability that the randomly selected ball is red or blue? 2) If one ball is randomly drawn from the urn, what is the probability that the randomly selected ball is numbered 1 or blue?
There are 4 balls in a bag: Red, Blue, Green and Yellow. In how many ways...
There are 4 balls in a bag: Red, Blue, Green and Yellow. In how many ways you can pick k balls from the urn of n with replacement?
For a certain​ candy, 10​% of the pieces are​ yellow, 10​% are​ red, 15​% are​ blue,...
For a certain​ candy, 10​% of the pieces are​ yellow, 10​% are​ red, 15​% are​ blue, 5​% are​ green, and the rest are brown. ​a) If you pick a piece at​ random, what is the probability that it is​ brown? it is yellow or​ blue? it is not​ green? it is​ striped? ​ b) Assume you have an infinite supply of these candy pieces from which to draw. If you pick three pieces in a​ row, what is the probability...
For a certain​ candy, 20​% of the pieces are​ yellow, 5​% are​ red, 15​% are​ blue,...
For a certain​ candy, 20​% of the pieces are​ yellow, 5​% are​ red, 15​% are​ blue, 10​% are​ green, and the rest are brown. ​ a) If you pick a piece at​ random, what is the probability that it is​ brown? it is yellow or​ blue? it is not​ green? it is​ striped? ​ b) Assume you have an infinite supply of these candy pieces from which to draw. If you pick three pieces in a​ row, what is the...
A bag contains 10 white, 12 blue, 13 red, 7 yellow, and 8 green wooded balls....
A bag contains 10 white, 12 blue, 13 red, 7 yellow, and 8 green wooded balls. A ball is selected from the bag, its color noted, then replaced. You then draw a second ball, note its color and then replace the ball. What is the probability of selecting 2 white balls? Round to the nearest ten-thousandth.
how many different ways are there to place 1 blue, 1 yellow, 1 red, 3 black,...
how many different ways are there to place 1 blue, 1 yellow, 1 red, 3 black, 2 green, 1 brown, 1 white, and 3 gray books on the shelf assuming that we cannot distinguish books of the same color.v
Consider an urn with 20 red balls, 30 blue balls, and 15 yellow balls, along with...
Consider an urn with 20 red balls, 30 blue balls, and 15 yellow balls, along with a standard deck of cards (jokers excluded). Consider the following events: A = {a red or blue ball is drawn}, B = {a yellow or blue ball is drawn}, C = {a heart is drawn}, D = {a face card is drawn}. Assuming you’ll draw a single ball and a single card, calculate the following. 1. p(A), p(C). 2. p(B and C), p(C and...
An urn contains 10 red balls, 7 green balls, and 3 yellow balls. Draw 5 balls....
An urn contains 10 red balls, 7 green balls, and 3 yellow balls. Draw 5 balls. What's the probability that you draw 2 red, 2 green, and 1 yellow? (Same experiment as above) What's the probability that you draw 2 red, 1 green, and 2 yellow?
There are 5 red, 4 blue, 6 green and 3 black balls in a box. Ahmed...
There are 5 red, 4 blue, 6 green and 3 black balls in a box. Ahmed draws 5 balls from the box at random. What is the probability that at least three of them are blue?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT