0% found this document useful (0 votes)
5 views2 pages

Match Case

Uploaded by

ayaan121640r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Match Case

Uploaded by

ayaan121640r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [ ]: Match case:

Match case is one of the conditional statement.


The purpose of match case statements is that
"To deal with predefined conditions or menu driven applications"
Syntax:
match(choice value):
case label1:
//block statement
case label2:
//block statement
case label3:
//block statement
case labeln:
//block statement
case default:
//statements
end is predefined parameter in print function
that controls what characters are printed at the end of the printed text.

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 [ ]: Match case is one of the conditional statement


The purpose of match case statement is that
"to deal with with predefined conditions or menudriven applications"

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 _:

Cell In[8], line 11


case ch=='a' or ch=='e' or ch=='o' or ch=='i' or ch=='u':
^
SyntaxError: invalid syntax

In [9]: Write a program to check whether a character is uppercase or lowercase.


Character is uppercase alphabet if(ch >= 'A' and ch <= 'Z').
Character is lowercase alphabet if(ch >= 'a' and ch <= 'z').
If none of the above conditions met, then character is "not an alphabet."

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

Cell In[9], line 1


Write a program to check whether a character is uppercase or lowercase.
^
SyntaxError: invalid syntax

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

In [16]: #Range function is used to generate sequence of numbers.


#Range function return type is sequence of numbers
numbers=range(4)#single argument
print(numbers)
print(list(numbers))

range(0, 4)
[0, 1, 2, 3]

In [17]: numbers=range(100,201)#start end


print(numbers)
print(list(numbers))

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]

In [18]: numbers=range(100,201,4)#start end stepsize


print(numbers)
print(list(numbers))

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.

In [21]: for i in range(10):


print("hai")

hai
hai
hai
hai
hai
hai
hai
hai
hai
hai

In [22]: for i in range(10,20):


print(i,end=" ")

10 11 12 13 14 15 16 17 18 19

In [23]: for i in range(10,20,4):# by default step size is 1


print(i,end=" ")

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 [ ]:

You might also like