A Gumball machine has a number of different colors available: There are a random number of yellow, blue, white, green, black, purple, silver, cyan and magenta gumballs and one red gumball. With a pocket full of quarters, you have set your heart on getting that single red gumball. So, write a program that will simulate buying gumballs until you get the red one.
(Using Python) To start with, the number of gumballs for each color are randomly chosen as follows.
Yellow - Between 10 and 15
Blue - Between 1 and 10
White - Between 6 and 15
Green - Between 10 and 25
Black - Between 1 and 12
Purple - Between 5 and 10
Silver - Between 4 and 6
Cyan - Between 5 and 12
Magenta - Between 0 and 10
Red - 1 and only 1
You should first print out how many of each color are available at the start of your gumball buying spree. Then, you should randomly pick gumballs and print them out until you randomly pick the red one. At the end, you should print out how much total money you spent and also print out which color(s) you bought the most (which may be a tie!)
A sample run might look something like this:
Welcome to the CIMS Gumball Machine Simulator
You are starting with the following Gumballs:
5 Yellow
3 Blue
6 White
17 Green
6 Black
8 Purple 4 Silver
10 Cyan
2 Magenta
and 1 Yellow
Here are your random purchases:
Green
Purple
Yellow
Green
Magenta
Magenta
Green
Yellow
Yellow
Red
You purchased 10 Gumballs, for a total of $2.50.
The color(s) purchased most: Yellow Green
Here , i think their is one-misprint that is the yellow gumball is printed twice at the begining but no red gumball, so I corrected in in the code but i you have any doubt please feel free to ask.
Code :
import random
#create a list of Gumball
gumball = ["Yellow", "Blue", "White", "Green", "Black", "Purple",
"Silver", "Cyan", "Magenta", "Red"]
#create a list of numbers of Gumball of each type available
gumball_count = [11, 3, 6, 17, 5, 8, 5, 7, 4, 1]
total_gumball_purchased = 0
#a list to store gumball of each type purchased
purchased_gumball_list = [0, 0, 0, 0, 0, 0, 0, 0, 0,
0]
#starting of the program
print("Welcome to the CIMS Gumball Machine Simulator")
print("You are starting with the following Gumballs:
")
#print all available Gumballs and their count
for count, gmball in zip(gumball_count, gumball):
print(count, gmball)
print("Here are your random purchase")
while True:
gumball_choice = random.choice(gumball)
total_gumball_purchased = total_gumball_purchased + 1
purchased_gumball_list[gumball.index(gumball_choice)] =
purchased_gumball_list[gumball.index(gumball_choice)] + 1
print(gumball_choice)
if gumball_choice == "Red":
break
print("You purchased {0} gumball for a total of
{1}".format(total_gumball_purchased,
(0.25*total_gumball_purchased)))
#get max from list
get_max = max(purchased_gumball_list)
print("The color(s) purchased most : ", end="")
#print each gumball where index value is equal to get max
for index in range(len(purchased_gumball_list)):
if purchased_gumball_list[index] == get_max:
print(gumball[index], end=" ")
-------------------------------------------------------------------------------------------------------------------------------------
Screenshots :

-------------------------------------------------------------------------------------------------------------------------------------------------
Output :




A Gumball machine has a number of different colors available: There are a random number of...
Which of the equations below regarding colors is correct? a. white = red + green + blue (light) b. black = cyan + magenta + yellow (pigment) c. red = green + blue (light) d. cyan = yellow + magenta (pigment)
Question 1 1 pts How many secondary colors are there for visible light? What are their names? Two -- Black and White Four -- Red, Green, Blue, and White Three -- Magenta, Cyan, and Yellow One -- Black > Question 2 1 pts How many primary colors are there for visible light? What are their names? Three -- Red, Green, and Blue OTWO -- White and Black One -- White Four -- Cyan, Magenta, Yellow, and Black
solve 30-32
QUESTION 30 What colors of ink are used to print full-color pictures? a. magenta and cyan, plus black b. red, green, blue plus black c. red, green, yellow, blue plus black d. magenta, yellow, cyan plus black e. magenta, yellow, cyan, red, green, blue plus black QUESTION 31 How long will it take a microwave signal to travel to and return from a satellite at an orbit of 1.2x106m? a. 0.004s b. 2500 sec c. 0.008s a d....
The figure shown is used to indicate combinations of color primaries for subtractive mixing of colors. Which one of the following is true? 4 5 3 2 6 O (A) 1-green, 6- magenta, 4-yellow (B) 1-yellow, 4-blue, 7- white (C) 1-cyan, 5- green, 7- white O (D) 1-magenta, 5-red, 7-black
Python 3
The number of socks of different colors in a drawer full of colored socks is represented as follows: socks = { 'red':4 , 'blue':15, 'white':10, 'black':20, 'brown':11 } a) Draw a simple bar chart to represent this information b) Convert the dictionary into a list containing the color names (as strings) repeated as many times as given in the dictionary. That will look like ['red', 'red', 'red', 'red','blue'....., 'brown']. Do not do this manually. Write a program that...
1. Fill in the resistance values for the following color codes: a) blue gray red silver b) yellow purple brown gold c) brown orange green gold d) white black orange gold e) green blue yellow silver f) red green black gold 2. Fill in the circle with the correct type of meter (V, A,2) a) b) c) 3. Which meter(s) will measure the total current in the circuit shown below? A C, D &E (circle correct answer) A & B...
There are 8 fags of di fferent colors -- white, black, red, yellow, blue, green, purple and brown. Suppose that by putting any 3 of the 8 flags together, it conveys a signal. (a) Assume that the sequence of the colored flags matters. For example, the sequence of white, black and red represents a diff erent signal than black, red, and white. How many signals can be made by choosing 3 flags out of the 8? (b) Now suppose that...
Q1. Find measurement of resistors: Resistor 1: blue - violet - black - orange - gold Resistor 2: orange-orange-brown-brown-red Resistor 3: orange-orange - red -red-gold Resistor 4: blue - violet - red - brown - gold Resistor 5: yellow - red - brown-brown-silver Q2. What color code designates: 52, 10% Color Black Brown Red Orange Yellow Green Blue Violet Digit Multiplier Tolerance (%) 0 10° (1) 1 L 10 2 10% 3 103 4 104 5 10 0.5 6 0.25...
In a recently purchased pack of peanut M&M's, 9 of the 65 peanut M&M's were brown. If we were to use this sample to create a 95% confidence interval, we would get an interval (0.055 < p < 0.222). The Task - buy a package of M&Ms, the package must be larger than a fun-size (+50 pieces) - determine the claimed population percentage of each color M&M (see below) - record the total number of each color M&M in your...
M&M plain candies come in various colors. According to the M&M/Mars Department of Consumer Affairs, the distribution of colors for plain M&M candies is as follows Color Purple Yllow Red OrangeGre en Blue 10% Brown 10% Percentage 17% 2390 2390 9% 8% Suppose you have a large bag of plain M&M candies and you choose one candy at random (a) Find P(green candy or blue candy) Are these outcomes mutually exclusive? Why? Yes. Choosing a green and blue M&M is...