Match Case
Match Case
In [6]: #Program for call all types of arithmetic operations by using match case statement
print("*"*50)
print("\tArithemetic Operations")
print("*"*50)
print("\t1.Addition")
print("\t2.Substraction")
print("\t3.Multiplication")
print("\t4.Division")
print("\t5.Floor division")
print("\t6.Modulo division")
print("\t7.Power")
print("*"*50)
ch=int(input("enter your choice"))
match ch:
case 1:
print("enter two values for addition\n")
a,b=map(int,input().split())
c=a+b
print(c)
case 2:
print("enter two values for substraction\n")
a,b=map(int,input().split())
c=a-b
print(c)
case 3:
print("enter two values for multiplication\n")
a,b=map(int,input().split())
c=a*b
print(c)
case 4:
print("enter two values for division\n")
a,b=map(int,input().split())
c=a/b
print(c)
case 5:
print("enter two values for floor division\n")
a,b=map(int,input().split())
c=a//b
print(c)
case 6:
print("enter two values for modulo division\n")
a,b=map(int,input().split())
c=a%b
print(c)
case 7:
print("enter two values for power\n")
a,b=map(int,input().split())
c=a**b
print(c)
case _:
print("enter valid input\n")
**************************************************
Arithemetic Operations
**************************************************
1.Addition
2.Substraction
3.Multiplication
4.Division
5.Floor division
6.Modulo division
7.power
**************************************************
enter two values for substraction
11
In [9]: #Program for Find the area of Different Areas using match case statement
import math
print("*"*50)
print("\tFind Different Areas using match case")
print("*"*50)
print("\t1.Rectangele")
print("\t2.SQuare")
print("\t3.Circle")
print("\t4.Triangle")
print("*"*50)
ch=int(input("enter your choice"))
match ch:
case 1:
print("enter length and breadth\n")
l,b=map(int,input().split())
a=l*b
print(a)
case 2:
print("enter the side\n")
side=int(input())
a=side*side
print(a)
case 3:
print("enter the radius\n")
r=int(input())
a=math.pi*r*r
print(a)
case 4:
print("enter height and breadth\n")
h,b=map(int,input().split())
a=1/2*h*b
print(a)
case _:
print("enter valid input")
**************************************************
Find Different Areas using match case
**************************************************
1.Rectangele
2.SQuare
3.Circle
4.Triangle
**************************************************
enter valid input
In [8]: print("*"*50)
print("\tArithmetic operations using match case")
print("*"*50)
print("\t1.Addition")
print("\t2.Substration")
print("\t3.multiplication")
print("*"*50)
print("enter your choice")
ch=input()
match ch:
case 'a':
print("vowel")
case _:
Input Format:
Single line input containing, one character.
Output Format:
Print output according to the discription.
Sample I/O:
Input 1:
A
Output 1:
uppercase alphabet
Input 2:
a
Output 2:
lowercase alphabet
Input 3:
1
Output 3:
not an alphabet
In [13]: ch=input()
print(ord(ch))
print(chr(97))
97
a
In [ ]: Write a Program to print the color name by taking the Color code as input.
V -> Violet
I -> Indigo
B -> Blue
G -> Green
Y -> Yellow
O -> Orange
R -> Red
Input Format:
Single line input containing, one character.
Output Format:
Print the output according to the discription.
Sample I/O:
Input 1:
G
Output 1:
Green
Input 2:
B
Output 2:
Blue
In [14]: #Program for call all types of arithmetic operations by using match case statement
print("*"*50)
print("\tPrint Colour Name")
print("*"*50)
print("\tV -> Violet")
print("\tI -> Indigo")
print("\tB -> Blue")
print("\tG -> Green")
print("\tY -> Yellow")
print("\tO -> Orange")
print("\tR. -> Red")
print("*"*50)
ch=input()
match ch:
case 'V':
print("V -> Violet\n")
case 'I':
print("I -> Indigo\n")
case 3:
print("B -> Blue\n")
case 4:
print("G -> Green\n")
case 5:
print("Y -> Yellow\n")
case 6:
print("O -> Orange\n")
case 7:
print("R. -> Red\n")
case _:
print("enter valid input\n")
#a,b=map(int,input().split())
#c=a-b
#print(c)
**************************************************
Print Colour Name
**************************************************
V -> Violet
I -> Indigo
B -> Blue
G -> Green
Y -> Yellow
O -> Orange
R. -> Red
**************************************************
V -> Violet
range(0, 4)
[0, 1, 2, 3]
range(100, 201)
[100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
194, 195, 196, 197, 198, 199, 200]
range(100, 201, 4)
[100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 148, 152, 156, 160, 164, 168, 172, 176, 180, 184, 188, 192, 196, 200]
In [ ]: The range() function is commonly used in for loop to iterate the loop a certain number of times.
hai
hai
hai
hai
hai
hai
hai
hai
hai
hai
10 11 12 13 14 15 16 17 18 19
10 14 18
In [ ]: Loops:Iterative Statements
To execute block of satements repeatedly we use Loops
two types of loops in python:
1.for loop
2.while loop
***no do while loop in python***
In [ ]: # while loop is used to execute block of statements repeatedly until given condtion is true
Syntax:
while condtion:
//body of the loop
(or)
while(condtion):
//body of the loop
In [1]: n=int(input())
i=1
while i<=n:
print(i,end="aditya ")
i=i+1
1aditya 2aditya 3aditya 4aditya 5aditya 6aditya 7aditya 8aditya 9aditya 10aditya
In [ ]: