Write indented and documented program in python for To display the colours of rainbow as per the user's choice.
Answers
Answer:
PROGRAM TO PRINT COLOURS OF RAINBOW ACCORDING TO THE NO. INPUTTED BY THE USER
#include,stdio.h>
#include<conio.h>
void main()
{
int ch;
printf("INPUT A NUMBER\n");
scanf("%d",&ch);
switch(ch)
{
case 6: printf("Red");
break;
case 5 :
printf(" Orange");
break;
case 4 :
printf(" Yellow");
break;
case 3 :
printf(" Green");
break;
case 2 :
printf(" Blue");
break;
case 1 :
printf(" Indigo");
break;
case 0 :
printf(" Violet");
break;
default : ("wrong input ");
}
}
The below Python code displays the Colours of rainbow as per the Users Choice.
CODE:
from term color import colored
colors = ['red', 'yellow', 'green', 'cyan', 'blue', 'magenta']
for n in range(len(colors)):
print(" " * n, end="")
for color in reversed(colors):
print(colored('X', color), end="")
print()
for n in range(len(colors)):
print(" " * (5-n), end="")
for color in reversed(colors):
print(colored('X', color), end="")
print ()
Hence, by the above code you will get your Desired Output.
#SPJ2