Question
write a Python program that displays a randomly colored window, and asks the user to guess the red-green-blue (RGB) values of the color. The program
write a Python program that displays a randomly colored window, and asks the
user to guess the red-green-blue (RGB) values of the color. The program also times how long it takes the user
to make his guesses. Read this entire document carefully before attempting to write any code.
Here is some pseudocode for your program:
*# Make a random color.
Pop up an information box saying "I will now pop up a randomly colored window ".
Pick a random number in the range 0 through 255 (both inclusive), for the red component of the
random color; assign it to a variable, which is appropriately named (for example, r).
Do something similar to pick random values for the green and blue components; assign these values
to their own variables.
Note: the random choice of the RGB color components means that every time your program is run, it
picks a different value for each of them.
Make a color from the random RGB values picked before; assign it to a variable appropriately named.
* # Create a picture with the random color, and display the picture.
Make a 300px (wide) x 200px (tall) picture in that color, and show this picture.
* # Ask the user to guess the color.
Pop up an information box saying "I will now see if you can guess the RGB values of this random color ".
Ask the user to guess the red level, and assign the input value to a variable, which is appropriately
named (for example, rGuess).
Do something similar to ask the user for his guesses for the green and blue components; assign these
values to their own variables.
*# Show the user how his guess compares with the actual color, by displaying colors in the same
window.
Make a color from the RGB values the user guessed; assign it to a variable appropriately named.
Fill the bottom third of the randomly colored picture (which is now displayed on screen) with the
color the user guessed, and refresh the picture on screen.
*# Show the user comparatively the RGB values of the random color and of the color they guessed.
First fill the middle third of the picture with white.
Then draw a message on this white area of the picture that shows the RGB values of the random
color.
Below the first message, still in the white area, draw a second message that shows the RGB values of
the guessed color.
The messages should be placed approximately halfway down the picture.
Note: to draw some text on a picture, in a certain style (meaning in a certain font type and font size),
you can use the following statements:
myStyle = makeStyle(sansSerif, bold, 20)
addTextWithStyle(picture, where_x, where_y, text to add to picture, myStyle)
Note that you must replace the text in blue and italic font above with the appropriate code yourself.
* Print in the console a message showing how many seconds it took the user to make his color guesses.
*Programming style and comments.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started