Python Basic: Tập thể dục-8 với giải pháp
Viết một chương trình Python để hiển thị các màu đầu tiên và cuối cùng từ danh sách sau.
color_list = ["màu đỏ", "màu xanh lá cây", "trắng", "đen"]]]
Trình bày bằng hình ảnh:
Giải pháp mẫu:-:-
Mã Python:
color_list = ["Red","Green","White" ,"Black"]
print[ "%s %s"%[color_list[0],color_list[-1]]]
Đầu ra mẫu:
Red Black
Flowchart:
Trực quan hóa thực thi mã Python:
Công cụ sau đây trực quan hóa những gì máy tính đang làm từng bước khi nó thực hiện chương trình đã nói:
Trình chỉnh sửa mã Python:
Có một cách khác để giải quyết giải pháp này? Đóng góp mã của bạn [và nhận xét] thông qua Disqus.
Trước đây: Viết chương trình Python để chấp nhận tên tệp từ người dùng và in phần mở rộng của đó. [trích xuất ngày từ exic_st_date]. Write a Python program to accept a filename from the user and print the extension of that.
Next: Write a Python program to display the examination schedule. [extract the date from exam_st_date].
Python: Lời khuyên trong ngày
Thử-Catch-Else Construct:
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]
Phân đoạn chương trình được đưa ra dưới đây chấp nhận một ký tự từ bàn phím và in tên của màu tương ứng, e. g., Nếu người dùng nhập ký tự r, nó in màu đỏ. Tuy nhiên, nó chỉ xử lý ba màu, cụ thể là màu đỏ, xanh lá cây và màu xanh lam. Nhân vật được nhập từ bàn phím trước tiên được chấp nhận với màu thay đổi [thuộc loại char] và sau đó được kiểm tra trong câu lệnh Switch. Chương trình bao gồm ba trường hợp tương ứng với màu đỏ, xanh lá cây và xanh dương. Lưu ý rằng các giá trị trường hợp là các hằng số ký tự, R, ’G, và‘ B. Mỗi trường hợp bao gồm một câu lệnh PRINTF để in tên màu theo sau là một câu lệnh break. Đầu ra của chương trình chứa mã trên được hiển thị bên dưới.
The character entered from the keyboard is first accepted in variable color [of type char] and then tested in the switch statement. The program includes three cases corresponding to the
colors red, green, and blue. Note that the case values are character constants’ R,’ ‘G’ and ‘B.’ Each case includes a printf statement to print the color’s name followed by a break statement. The output of the program containing the above code shown below.#include
void main[] {
char color;
clrscr[];
printf["Enter character [R/G/B]: "];
color= getchar[];
switch [color] {
case 'R':
printf ["Red"] ;
break;
case 'G':
printf["Green"];
break;
case 'B':
printf["Blue"];
break;
}
getch[];
}
Trong bài viết này, chúng tôi sẽ đề cập đến cách in văn bản màu bằng Python bằng một số phương thức để xuất văn bản màu vào thiết bị đầu cuối trong Python. & NBSP;how to print colored text in Python using several methods to output colored text to the terminal in Python.
Những cách phổ biến nhất để làm điều này là sử dụng:
- Sử dụng mô -đun Colorama
- Sử dụng mô -đun TermColor
- Sử dụng mã ANSI trong Python
Phương pháp 1: In văn bản màu sử dụng mô -đun Colorama
Mô-đun Colorama là in hình nền tảng của văn bản màu sau đó có thể được thực hiện bằng cách sử dụng tốc ký không đổi Colorama cho các chuỗi thoát ANSI: & nbsp;is aCross-platform printing of colored text can then be done using Colorama’s constant shorthand for ANSI escape sequences:
Ví dụ 1: & NBSP; Chương trình Python để in văn bản màu đỏ với nền màu xanh lá cây. Python program to print red text with green background.
Python3
from
colorama
import
Fore, Back, Style
print
[Fore.RED
____10
Red Black1
Red Black2
print
Red Black4
Red Black0
Red Black6
Red Black2
print
Red Black9____10
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]1
Red Black2
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]4
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]7
Red Black2
Output:
Ví dụ 2: Chương trình Python để in văn bản màu xanh lá cây với nền màu đỏ. Python program to print green text with red background.
Python3
from
colorama
import
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }2
from
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }4
import
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }6
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }7
Các
Output:
Phương pháp 2: In văn bản màu sử dụng mô -đun TermColor
Mô -đun TermColor là một mô -đun Python cho định dạng màu ANSII cho đầu ra trong thiết bị đầu cuối. & NBSP; is a python module for ANSII Color formatting for output in the terminal.
Ví dụ: Chương trình Python để in văn bản và nền màu.Python program to print colored text and background.
Python3
import
from
7
from
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }4
import
colorama
1colorama
2colorama
3 colorama
4from
0from
1colorama
7colorama
8colorama
3import
0__1
print
import
6
import
7from
0from
1from
2from
1from
4
Red Black2
Fore, Back, Style
4 Fore, Back, Style
5Fore, Back, Style
6 Fore, Back, Style
7colorama
7____41print
0
Red Black2
print
2from
0
Red Black2
print
2print
6
Red Black2
print
8 print
9[Fore.RED
0 [Fore.RED
1
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }______
[Fore.RED
5[Fore.RED
6[Fore.RED
7[Fore.RED
8colorama
3
Red Black00
Red Black2
Các
Output:
Phương pháp 3: In văn bản màu bằng mã ANSI trong Python
Cách phổ biến nhất để in văn bản màu là bằng cách in trực tiếp các chuỗi thoát ANSI. Điều này có thể được phân phối ở các định dạng khác nhau như: & nbsp;
Ví dụ 1: Xây dựng các chức năng để gọi & nbsp;
Chúng ta có thể xây dựng các chức năng để gọi các hàm có tên màu cụ thể để thực hiện chuỗi thoát ANSI có liên quan. Dưới đây là chương trình Python để in văn bản và nền màu
Python3
Fore, Back, Style
4
Red Black15
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
Red Black18
Red Black19
Red Black20
Red Black21
Fore, Back, Style
4
Red Black23
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
Red Black26
Red Black19
Red Black20
Red Black21
Fore, Back, Style
4
Red Black31
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
Red Black34
Red Black19
Red Black20
Red Black21
Fore, Back, Style
4
Red Black39
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
Red Black42
Red Black19
Red Black20
Red Black21
Fore, Back, Style
4
Red Black47
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
Red Black50
Red Black19
Red Black20
Red Black21
Fore, Back, Style
4
Red Black55
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
Red Black58
Red Black19
Red Black20
Red Black21
Fore, Back, Style
4
Red Black63
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
Red Black66
Red Black19
Red Black20
Red Black21
Fore, Back, Style
4
Red Black71
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
Red Black74
Red Black19
Red Black20
Red Black21
Red Black78
Red Black79
Red Black2
Red Black81
Red Black82
Red Black2
Red Black84
Red Black85
Red Black2
Red Black87
Red Black88
Red Black2
Red Black84
Red Black85
Red Black2
Output:
Ví dụ 2: Xây dựng một lớp màu
Tạo một lớp để phân bổ nền và màu tiền cảnh và gọi chúng. & Nbsp; bên dưới là chương trình Python để in văn bản và nền màu.
Python3
Red Black93
Red Black94
Red Black95
colorama
3 Red Black97
Red Black98
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]00
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]01
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]03
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]04
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]06
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]07
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]09
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]10
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]11
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]13
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]14
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]15
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]17
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]18
Red Black93
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]20
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]222223
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]24
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]26
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]28
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]30
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]32
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]34
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]36
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]38
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]40
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]42
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]44
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]46
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]48
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]50
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]52
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]54
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]56
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]58
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]60
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]62
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]64
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]66
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]68
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]70
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]72
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]74
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]76
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]78
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]80
[Fore.RED
5
Red Black93
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]83
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]22223
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]87
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]26
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]91
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]30
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]95
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]34
colorama
3 try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]99
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]38
colorama
3 #include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }03
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]42
colorama
3 #include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }07
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]46
colorama
3 #include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }11
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]50
colorama
3 #include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }15
print
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }17
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }18
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }19
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }20
Red Black2
print
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }23
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }18
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }19
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }20
Red Black2
Output:
Ví dụ 3: Chức năng lặp lại
Chúng ta có thể thiết kế trình tự, chức năng, các chức năng của Iterating & tự tạo và tự tạo;
Python3
Fore, Back, Style
4
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }29
[Fore.RED
5print
8
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }32
[Fore.RED
0 [Fore.RED
1try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }36
[Fore.RED
4try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
print
8 #include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }40
[Fore.RED
0 [Fore.RED
1try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6______34441____
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }46
[Fore.RED
4#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }48
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }49
colorama
3 #include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }51
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }48
print
8 #include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }54
[Fore.RED
0 [Fore.RED
1try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }58
from
1#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }60
[Fore.RED
4Is
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }62
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }49
Red Black0
colorama
3 #include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }77
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }48
print
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }86
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]21
print
try: foo[] except Exception: print["Exception occured"] else: print["Exception didnt occur"] finally: print["Always gets here"]6
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }90
Red Black2
#include void main[] { char color; clrscr[]; printf["Enter character [R/G/B]: "]; color= getchar[]; switch [color] { case 'R': printf ["Red"] ; break; case 'G': printf["Green"]; break; case 'B': printf["Blue"]; break; } getch[]; }92
Output: