Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions