0% found this document useful (0 votes)
7 views5 pages

CS-IP Practicals 11th 11-15

The document contains practical Python programs that include pattern matching in lists, displaying patterns, working with dictionaries, checking for anagrams, and counting words with specific lengths. Each program is structured with an aim, algorithm, code, and result, demonstrating various programming concepts. The output of each program is also provided to verify successful execution.
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)
7 views5 pages

CS-IP Practicals 11th 11-15

The document contains practical Python programs that include pattern matching in lists, displaying patterns, working with dictionaries, checking for anagrams, and counting words with specific lengths. Each program is structured with an aim, algorithm, code, and result, demonstrating various programming concepts. The output of each program is also provided to verify successful execution.
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/ 5

PRACTICAL PROGRAMS

Note:
1. Each program should begin from a new page.
2. Write Aim, Algorithm, Program and Result on right side.(Ruled side)
3. Output should be on the left side. (Unruled side)

Index:

11. Pattern Matching in list


12. Display Pattern
13. Dictionary
14. Anagram
15. Count of words with length <= 4 from a list

PROGRAM-11
Aim:

Write a python program to get the list of strings from the user and display the strings which start
with character ‘b’ or ‘B’.

Algorithm:

1. Start
2. Get a list from the user and save it in variable l.
3. Traverse the list using a for loop, access each string.
4. Check whether the first character of the string is ‘b’ or ‘B’. If so, then display the string.
5. Stop

Program:

l = eval(input('Enter the list of strings:\t'))


for i in l:
if i[0] in 'bB':
print(i)

Result:

Python program to get the list of strings from the user and display the strings which start with
character ‘b’ or ‘B’ is executed successfully and output is verified.

Output:

Enter the list of string: ['Arc', 'Be', 'or', 'bee']


Be
Bee
PROGRAM: 12
Aim:

Write a python program to display the following pattern:


A
AB
ABC
ABCD

Algorithm:

1. Start
2. Get the no. of rows from the user and save it in a variable n.
3. Create a for loop with iterating variable ‘i’ and iterate it n times, execute lines 4 to 9.
4. Initialise variable a with value 65.
5. Display ' ' * (n – i +1).
6. Create a second for loop for columns, iterate it for range(row), execute lines 7 and 8.
7. Display the character A using chr(a). Set the end parameter of print to ' '.
8. Increment the value of a by 1.
9. Print a new line.
10. Stop

Program:

n= int (input('Enter the no. of row:\t'))


for i in range(1, n+1) :
a=64
print(" "*(n-i), end = ' ')
for j in range(i):
a= a+1
print(chr(a), end=' ')
print( )

Result:
Python program to display the pattern is executed successfully and the output is verified.

Output:

Enter the no. of row: 3


A
AB
ABC
ABCD

PROGRAM: 13

Aim:
Write a python program to get a dictionary from the user which contains name as key, mark as
value and display the names which are having mark greater than 75.

Algorithm:

1. Start
2. Get the dictionary from user and save it in a variable ‘d’.
3. Create a for loop with iterating variable ‘i’ to access the values of the dictionary. Execute
line 4.
4. Check whether d[i] is greater than 75, if so display ‘i’.
5. Stop

Program:

d = eval (input('Enter the dictionary:\t'))


for i in d:
if d[i] > 75:
print(i)
Output:

Enter the dictionary: {'Arya' : 85, 'Cabel' : 45, 'Sunita' : 67, 'Abin' : 78}
Arya
Abin

PROGRAM: 14

Aim:

Write a python program to get a List containing two strings and check whether the strings are
anagram or not.

Algorithm:

1. Start
2. Get a list from the user and save it in L.
3. Sort the first and second element of the string and save it in variables m and n.
4. Check whether m and n are equal. If so, display strings are anagram.
5. Otherwise, display strings are not anagram.
6. Stop

Program:

L = eval (input('Enter the list with 2 strings:\t'))


m = sorted(L[0])
n = sorted(L[1])
if m==n:
print('Strings', L[0], 'and', L[1], ' are Anagram')
else:
print('Strings', L[0], 'and', L[1], ' are not Anagram')
Result:

Python program to get a List containing two strings and check whether the strings are anagram or
not is successfully executed and output is verified.

Output:

Enter the list with 2 strings: ['post' , 'stop']


Strings post and stop are Anagram

Enter the list with 2 strings: ['cast' , 'stack']


Strings cast and stack are not Anagram

PROGRAM: 15

Aim:

Write a python program to get a List from the user, count the number of words which are having
length less than or equal to four and display the count.

Algorithm:

1. Start
2. Get a list from the user and save it in variable l.
3. Initialise a variable c as zero.
4. Traverse the list to access element using a for loop with iterating variable ’i’. Execute line
4.
5. Check whether the length of i is less than or equal to 4. If so, increment the value of c with
1.
6. Display the value of c.
7. Stop

Program:

l = eval (input('Enter the list of strings:\t'))


c=0
for i in l:
if len(i) <= 4:
c += 1
print('The count of words which have length less than or equal to 4 is: ', c)

Result:

Python program to get a List from the user, count the number of words which are having length
less than or equal to four and display the count is executed successfully and the output is verified.

Output:

Enter the list of strings: ['cast' , 'stack', 'cat', 'Grape', 'post' , 'Orchid', 'pet']
The count of words which have length less than or equal to 4 is: 4

You might also like