0% found this document useful (0 votes)
45 views6 pages

16to20 Programs

This document contains 20 programming exercises in Python. It includes exercises to count the number of persons between ages 60-90 in a list, compute the transpose of a matrix, perform addition, subtraction and multiplication on two matrices, count the occurrence of vowels in a string, and count the total number of vowels in a word. The document provides the name, subject code, and roll number for each programming exercise.

Uploaded by

Sambhav Gandhi
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)
45 views6 pages

16to20 Programs

This document contains 20 programming exercises in Python. It includes exercises to count the number of persons between ages 60-90 in a list, compute the transpose of a matrix, perform addition, subtraction and multiplication on two matrices, count the occurrence of vowels in a string, and count the total number of vowels in a word. The document provides the name, subject code, and roll number for each programming exercise.

Uploaded by

Sambhav Gandhi
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/ 6

Programming in Python Laboratory Name: Sparsh Manni

Subject Code: UGCA 1917 Roll Number: 3212

16: Count number of persons of age above 60 and


below 90.

#Age of persons is stored in l

l=[12,65,71,32,45,79,59]
c=0

for i in l:
if i>=60 and i<=90:
c=c+1
print("Number of persons having age graeter than 60 and less than
90_",c)

Page 23
Programming in Python Laboratory Name: Sparsh Manni

Subject Code: UGCA 1917 Roll Number: 3212

17: Compute transpose of a matrix.

N=4
def transpose(A):
for i in range(N):
for j in range(i+1, N):
A[i][j], A[j][i] = A[j][i], A[i][j]
A = [ [2, 2, 2, 2],
[7, 7, 7, 7],
[3, 3, 3, 3],
[5, 5, 5, 5]]
transpose(A)
print("Modified matrix is")
for i in range(N):
for j in range(N):
print(A[i][j], " ", end='')
print()

Page 23
Programming in Python Laboratory Name: Sparsh Manni

Subject Code: UGCA 1917 Roll Number: 3212

18: Perform following operations on two matrices. 1)


Addition 2) Subtraction 3) Multiplication.

# importing numpy as np
import numpy as np
# creating first matrix
A = np.array([[1, 2], [3, 4]])
# creating second matrix
B = np.array([[4, 5], [6, 7]])

print("Printing elements of first matrix")


print(A)
print("Printing elements of second matrix")
print(B)
# adding two matrix
print("Addition of two matrix")

print(np.add(A, B))
# subtracting two matrix
print("Subtraction of two matrix")
print(np.subtract(A, B))
#multiply two matrix

Page 23
Programming in Python Laboratory Name: Sparsh Manni

Subject Code: UGCA 1917 Roll Number: 3212

res = A @ B
# print resulted matrix

print("multiplication of two matrix")


print(res)

Page 23
Programming in Python Laboratory Name: Sparsh Manni

Subject Code: UGCA 1917 Roll Number: 3212

19. Count occurrence of vowels.

# string of vowels
vowels = 'aeiou'
ip_str = input("Enter the words or a sentence _")

# make it suitable for caseless comparisions


ip_str = ip_str.casefold()

# make a dictionary with each vowel a key and value 0


count = {}.fromkeys(vowels,0)
# count the vowels
for char in ip_str:
if char in count:

count[char] += 1
print(count)

Page 23
Programming in Python Laboratory Name: Sparsh Manni

Subject Code: UGCA 1917 Roll Number: 3212

20. Count total number of vowels in a word.

# Python Program to Count Vowels in a String

str1 = input("Please Enter Your Own String : ")


vowels = 0

for i in str1:
if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u' or i == 'A'
or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
vowels = vowels + 1

print("Total Number of Vowels in this String = ", vowels)

Page 23

You might also like