Question: You will create a Python program that will accept user input of an English color value from a given range of colors and will return

You will create a Python program that will accept user input of an English color value from a given range of colors and will return the Spanish equivalent. You will use IF, ELIF, and ELSE statements along with comparison operators to evaluate the entered value and display the appropriate results to the user.

Instructions—Part 2

1. Print a string statement with a list of acceptable colors to the screen:

"Your color choices are red, blue, green, white or yellow." 

Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 2: Print Statements.

2. Prompt the user to enter a color value from the list. Assign the user input to a variable (i.e., userColor).

"Enter a color from the list above: "

Reference: Refer back to your readings in Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 3: Built-In Functions / Getting Input From the User.

3. Convert the color value entered to all lowercase for easier evaluation. Use the string function lower and store the lowercase color in a new variable (i.e., color).

Reference: Refer back to your readings in Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 8: Built-In String Operations.

4. Create a variable named validColor and set it to a value of true.

5. Using a series of IF/ELIF statements, evaluate the color and set a new variable (i.e., spanishColor) to the appropriate Spanish equivalent. Use a final else statement if a valid color was not entered, and assign the validColor flag to a value of false.

red = rojo

blue = azul

green = verde

white = blanco

yellow = amarillo

Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 5: The if Statement / Comparison Operators / The elif Statement / Using Many elif Statements.

6. Create a final IF/ELSE statement to evaluate the validColor flag. If a valid color was entered, use string concatenation to display the English color (color) and its Spanish equivalent (spanishColor). If not, display a message indicating a valid color was not entered.

Reference: Refer back to your readings in Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 2: Print Statements; Chapter 3: Built-In Functions / Concatenation.

 

 EXAMPLE OUTPUT—Part 2

Your color choices are red, blue, green, white or yellow.

Enter a color from the list above: rEd

The color red in Spanish is rojo

Your color choices are red, blue, green, white or yellow.

Enter a color from the list above: black

That is not a valid color for this program. Ese no es un color válido.

Step by Step Solution

3.36 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python program to convert user input color to spanish Python version 36 display list of acceptable c... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!