0% found this document useful (0 votes)
4 views

Class X_C_13 Practical File 2024-25

The document contains a series of Python programming tasks and exercises aimed at students, including checking if a number is odd or even, creating lists of odd and even numbers, and performing list operations. It also includes tasks for calculating total marks and percentages for subjects, determining income tax based on age and salary, and manipulating lists through various methods. Each task is accompanied by sample inputs and outputs to illustrate the expected functionality.

Uploaded by

Kahan Playzz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Class X_C_13 Practical File 2024-25

The document contains a series of Python programming tasks and exercises aimed at students, including checking if a number is odd or even, creating lists of odd and even numbers, and performing list operations. It also includes tasks for calculating total marks and percentages for subjects, determining income tax based on age and salary, and manipulating lists through various methods. Each task is accompanied by sample inputs and outputs to illustrate the expected functionality.

Uploaded by

Kahan Playzz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

12/4/24, 11:13 PM Class X_C_13 Kahan Shah

In [5]: print("I am Kahan")

I am Kahan

In [11]: # Task 1: WAP to check whether the given number is odd or even
n= int(input("Enter a number: "))
if n%2==0:
print("The number is even")
else:
print("The number is odd")

Enter a number: 3
The number is odd

In [5]: #Task 2: Create a list of odd and even numbers


s=int(input("Enter the number of inputs desired: "))
i=1
e=[]
o=[]
while i<=s:
n= int(input("Enter a number: "))
i=i+1
if n%2==0:
e.append(n)
else:
o.append(n)
print("Odd numbers are: ",o, "and even numbers are: ",e)

Enter the number of inputs desired: 6


Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 46
Enter a number: 57
Enter a number: 98
Odd numbers are: [1, 3, 57] and even numbers are: [2, 46, 98]

In [2]: #Task 3: Slicing and Indexing


A= ["Water",2,5,8,1.8,"34rtr"]
B= ["I","am","Groot"]
print (A[1:5])
A[-5:-2]==A[1:4]
print(A+B)

[2, 5, 8, 1.8]
['Water', 2, 5, 8, 1.8, '34rtr', 'I', 'am', 'Groot']

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 1/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah

In [23]: #Task 4: List Functions


A= [11,16,46,46,29,'abc','xyz']

len(A)
print(len(A))

A.append(50)
print(A)

A.extend([51,52,'pqr'])
print(A)

A.insert(4,"Kahan")
print(A)

x= A.count(11)
print (x)

x= A.index(46)
print(x)

A.remove(46)
print(A)

A.pop(3)
print(A)

7
[11, 16, 46, 46, 29, 'abc', 'xyz', 50]
[11, 16, 46, 46, 29, 'abc', 'xyz', 50, 51, 52, 'pqr']
[11, 16, 46, 46, 'Kahan', 29, 'abc', 'xyz', 50, 51, 52, 'pqr']
1
2
[11, 16, 46, 'Kahan', 29, 'abc', 'xyz', 50, 51, 52, 'pqr']
[11, 16, 46, 29, 'abc', 'xyz', 50, 51, 52, 'pqr']

In [16]: A=[1,5,4,2,3]

A.reverse()
print(A)

A.sort()
print(A)

for i in range(len(A)):
print (A[i])

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 2/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
[3, 2, 4, 5, 1]
[1, 2, 3, 4, 5]
1
2
3
4
5

In [10]: #Task 5: WAP to take elements from the user and put them in a list
A= []
n =int(input("Enter the number of elements for list: "))
for i in range(1,n+1):
a= int(input("Enter a number: "))
A.append(a)
print(A)

Enter the number of elements for list: 5


Enter a number: 12
Enter a number: 24
Enter a number: 36
Enter a number: 48
Enter a number: 60
[12, 24, 36, 48, 60]

In [16]: #Task 6: WAP to take numbers from the user, categorize them into odd and even and print two lists of odd and even numbers sepe
O= []
E= []
n =int(input("Enter the number of elements for list: "))
for i in range(1,n+1):
a= int(input("Enter a number: "))
if a%2==0:
E.append(a)
else:
O.append(a)
print("This is the list of odd numbers-",O,
"and this is the list of even numbers-",E)

Enter the number of elements for list: 5


Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
This is the list of odd numbers- [1, 3, 5] and this is the list of even numbers- [2, 4]

In [4]: #Lab Set-1


#(Q.1) Create a list of 6 elements using list and seperate them in even and odd elements lists

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 3/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
O= []
E= []
for i in range(1,7):
a= int(input("Enter a number: "))
if a%2==0:
E.append(a)
else:
O.append(a)
print("This is the list of odd numbers-",O,
"and this is the list of even numbers-",E)

Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
This is the list of odd numbers- [1, 3, 5] and this is the list of even numbers- [2, 4, 6]

In [1]: #(Q.2) Create a list of 10 elements using list and reverse them all
A=[]
for i in range(1,11):
n= int(input("Enter a number: "))
A.append(n)
A.reverse()
print(A)

Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: 8
Enter a number: 9
Enter a number: 10
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

In [4]: #(Q.3) Create a list of first 10 even numbers, add 1 to each list element and print the final list
A=[]
for i in range(1,21):
a=int(input("Enter a number"))
if a%2==0:
A.append(a+1)
print(A)

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 4/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
Enter a number2
Enter a number4
Enter a number6
Enter a number8
Enter a number10
Enter a number12
Enter a number14
Enter a number16
Enter a number18
Enter a number20
Enter a number22
Enter a number24
Enter a number26
Enter a number28
Enter a number30
Enter a number32
Enter a number34
Enter a number35
Enter a number36
Enter a number38
[3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]

In [3]: #(Q.4) WAP to compute total marks of different subjects. Also compute the percentage. Create a list to take subject and its ma
s=int(input("Enter the number of subjects: "))
TM=0
S=[]
M=[]
MP=[]
for i in range (0,s):
Sn=input("Enter name of the subject: ")
S.append(Sn)
m=int(input("Enter marks out of 80: "))
M.append(m)
p= (m/80)*100
MP.append(p)
TM= TM+m
print("Subjects:",S)
print ("Marks respectively:",M)
print ("Your percentages for marks of each subject respectively are: ",MP)

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 5/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
Enter the number of subjects: 6
Enter name of the subject: Mathematics
Enter marks out of 80: 80
Enter name of the subject: Science
Enter marks out of 80: 78
Enter name of the subject: SS
Enter marks out of 80: 76
Enter name of the subject: English
Enter marks out of 80: 76
Enter name of the subject: Sanskrit
Enter marks out of 80: 78
Enter name of the subject: AI
Enter marks out of 80: 80
Subjects: ['Mathematics', 'Science', 'SS', 'English', 'Sanskrit', 'AI'] Marks respectively: [80, 78, 76, 76, 78, 80] Your perc
entages for marks of each subject respectively are: [100.0, 97.5, 95.0, 95.0, 97.5, 100.0]

In [12]: #(Q.5) Pg 240, B. 9


# Conditions- Divisible by 7, Multiple of 5, Between 1200 and 2200
a=int(input("Enter the no. of inputs"))
for i in range(0,a):
n=int(input("Enter the number: "))
if n%35==0 and n>=1200 and n<=2200 :
print("The number is divisble by 7 and is a multiple of 5 ")
else:
print("The number is invalid")

Enter the no. of inputs3


Enter the number: 2800
The number is invalid
Enter the number: 2100
The number is divisble by 7 and is a multiple of 5
Enter the number: 2401
The number is invalid

In [2]: #(Q.6) WAP to take 10 sequential elements and store it in a list. Delete every second element and print the final list
Series1= []
for i in range (0,10):
n=(input("Enter n: "))
Series1.append(n)
for i in range(1,6):
Series1.pop(i)
print(Series1)

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 6/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
Enter n: 1
Enter n: 2
Enter n: 3
Enter n: 4
Enter n: 5
Enter n: 6
Enter n: 7
Enter n: 8
Enter n: 9
Enter n: 10
['1', '3', '5', '7', '9']

In [3]: #(Q.7) WAP to take monthly income of employees and calculate the annual income tax to be paid by them.
age=int(input("Enter age in years: "))
if age>=60 and age<=80:
minc= int(input("Enter monthly salary: "))
ainc= minc*12
if ainc<300000:
print("No Income Tax will be levied.")
elif ainc>=300000 and ainc<500000:
it= (ainc/20)
print("The annual income tax to be paid by you is",it)
elif ainc>=500000 and ainc<1000000:
it= (ainc/5)
print("The annual income tax to be paid by you is",it)
else:
it= (ainc*(3/10))
print("The annual income tax to be paid by you is",it)
else:
print("Your income tax could not be calculated because, your age does not fulfill the age validity criterion")

Enter age in years: 70


Enter monthly salary: 400000
1440000.0

In [6]: #Textbook exercise: Predict the outputs


#(Q.1)
T=100
print(T*2)

FALSE
TRUE

In [7]: #(Q.2)
for i in range(100):
print(i)

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 7/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 8/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 9/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
94
95
96
97
98
99

In [8]: #(Q.3)
number=0
while number<=5:
if number<=5:
number= number +1
print(number, end=" ")

1 2 3 4 5 6

In [13]: #(Q.4)
if 4 + 5 ==10:
print("TRUE")
else:
print("FALSE")
print("TRUE")

FALSE
TRUE

In [14]: #(Q.5)
x= [10.0, 11.0, 12.0]
y= x[1]
print(y)

11.0

In [17]: #(Q.6)
b=1
for a in range(1,10,2):
b+= a+2
print(b)

36

In [16]: #(Q.7)
name="Pooja"
age=15
print(name,"you are",age,"now, and", end=" ")
print("you will be", age+1,"next year")

Pooja you are 15 now, and you will be 16 next year

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 10/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah

In [18]: #(Q.8)
my_list= ['apple','banana','cherry','apple','grape']
result= my_list.count('apple')
print(result)

In [21]: #(Q.9)
my_list = [2,7,1,3,5]
my_list.sort( )

In [22]: #(Q.10)
my_list= [3, 1, 4, 4, 1, 5, 9, 2, 6, 5, 3, 5]
output= my_list.count(5)
print(result)

In [3]: #Lab Set-II


#(Q.1)WAP to extract the last digit of any number
a= int(input("Enter number: "))
p= a%10
print(p)

Enter number: 223009


9

In [13]: #(Q.2)WAP to extract the first digit of any number


n=int(input("Enter number "))
rev=0
while n>0:
dig=n%10
rev=rev*10+dig
n=n//10
p= rev%10
print(p)

Enter number 123


1

In [5]: #(Q.3)WAP to check whether the number is palindrome


n=int(input("Enter number "))
KS=n
rev=0
while n>0:
dig=n%10
rev=rev*10+dig
file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 11/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
n=n//10
if rev==KS:
print("It is a palindrome")
else:
print("Failure")
print(rev)

Enter number 313


It is a palindrome
313

In [8]: #(Q.4)WAP to print a pattern


rows=5
k=0
for i in range(rows,0,-1):
k= k+1
for j in range(1,i+1):
print(k, end=" ")
print()

1 1 1 1 1
2 2 2 2
3 3 3
4 4
5

In [12]: #(Q.5) WAP to print multiplication table of any number


n=int(input("Enter any number: "))
a=int(input("Enter the number of multiples you want: "))
for i in range(1,a+1):
print(n,"*",i,"=",i*n)

Enter any number: 7


Enter the number of multiples you want: 10
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70

In [10]: #(6.1) WAP to display below pyramid pattern


#1
#2 2
file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 12/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
#3 3 3
#4 4 4 4
#5 5 5 5 5
n = int(input("enter the no: "))
k=0
for i in range(1, n+1):
k= k+1
for j in range(1, i+1):
print(k, end=" ")
print()

enter the no: 5


1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

In [11]: #(6.2) WAP to display below pyramid pattern


#1
#1 2
#1 2 3
#1 2 3 4
#1 2 3 4 5
n = int(input("enter the no: "))
for i in range(1, n+1):
for j in range(1, i+1):
print(j, end=" ")
print()

enter the no: 5


1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

In [12]: #(6.3) WAP to display below pyramid pattern


"""
A
B B
C C C
D D D D
E E E E E
"""
n=70
for i in range(65,n):

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 13/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
for j in range(65,1+i):
print(chr(i), end=" ")
print()

A
B B
C C C
D D D D
E E E E E

In [13]: #(6.4) WAP to display the pattern given below-


"""
A
A B
A B C
A B C D
A B C D E
"""
n=int(input("Enter number of rows: "))
for i in range(1,n+1):
for j in range(65,65+i):
print(chr(j), end=" ")
print()

Enter number of rows: 5


A
A B
A B C
A B C D
A B C D E

In [15]: #(6.5) WAP to display the pattern given below-


"""
*
* *
* * *
* * * *
* * * * *
"""
n=int(input("Enter number of rows: "))
k=0
for i in range(1,n+1):
k+=1
for j in range(1,k+1):
print("*", end=" ")
print()

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 14/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
Enter number of rows: 5
*
* *
* * *
* * * *
* * * * *

In [3]: #(6.6) WAP to display Flyod's Triangle which is given as-


"""
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
And so on, until the Mth term which is the last term of the Nth row which is the last row.
"""
n=int(input("Enter number of rows: "))
k=1
for i in range(1,n+1):
for j in range(k,i+k):
print(j, end=" ")
k+=1
print()

Enter number of rows: 5


1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

In [18]: #(6.7) WAP to display the pattern given below-


"""
*
@ @
* * *
@ @ @ @
* * * * *
"""
a=int(input("Enter number of rows: "))
for i in range(1,a+1):
if i%2!=0:
for j in range(1,i+1):
print("*",end=" ")
else:
for j in range(1,i+1):

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 15/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
print("@",end=" ")
print()

Enter number of rows: 5


*
@ @
* * *
@ @ @ @
* * * * *

In [19]: #(6.8) WAP to display the pattern given below-


"""
*
1 2
* * *
1 2 3 4
* * * * *
"""
a=int(input("Enter number of rows: "))
for i in range(1,a+1):
if i%2!=0:
for j in range(1,i+1):
print("*",end=" ")
else:
for j in range(1,i+1):
print(j,end=" ")
print()

Enter number of rows: 5


*
1 2
* * *
1 2 3 4
* * * * *

In [ ]: #(6.9) WAP to display the pattern given below-


"""
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
"""
n = int(input("enter the no: "))
k=6
for i in range(n,0,-1):
k= k-1

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 16/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
for j in range(1, i+1):
print(k, end=" ")
print()

In [ ]: #(6.10) WAP to display the pattern given below-


"""
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
"""
n = int(input("enter the no: "))
for i in range(n,0,-1):
for j in range(1, i+1):
print(j, end=" ")
print()

In [ ]: #(6.11) WAP to display the pattern given below-


"""
E E E E E
D D D D
C C C
B B
A
"""
n=69
for i in range(n,64,-1):
for j in range(64,i):
print(chr(i), end=" ")
print()

In [ ]: #(6.12) WAP to display the pattern given below-


"""
A B C D E
A B C D
A B C
A B
A
"""
n=int(input("Enter number of rows: "))
for i in range(n,0,-1):
for j in range(65,65+i):
print(chr(j), end=" ")
print()

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 17/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah

In [1]: #(6.13) WAP to display the pattern given below-


"""
* * * * *
* * * *
* * *
* *
*
"""
n=int(input("Enter number of rows: "))
for i in range(n,0,-1):
for j in range(1,i+1):
print("*", end=" ")
print()

Enter number of rows: 5


* * * * *
* * * *
* * *
* *
*

In [20]: #(6.14) WAP to display Flyod's Triangle in inversion-


n=int(input("Enter number of rows: "))
k=1
for i in range(n,0,-1):
for j in range(k,i+k):
print(j, end=" ")
k+=1
print()

Enter number of rows: 3


1 2 3
4 5
6

In [5]: #(6.15)
n=int(input("Number of rows: "))
for i in range(n,0,-1):
if i%2!=0:
for j in range(1,i+1):
print("@",end=" ")
else:
for j in range(1,i+1):
print("*",end=" ")
print()

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 18/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
Number of rows: 5
@ @ @ @ @
* * * *
@ @ @
* *
@

In [9]: #(6.16) WAP to display the pattern given below-


"""
11111
2222
333
44
5
"""
n = int(input("enter the no: "))
k=0
for i in range(n,0,-1):
k= k+1
for j in range(1, i+1):
print(k, end=" ")
print()

enter the no: 5


1 1 1 1 1
2 2 2 2
3 3 3
4 4
5

In [29]: #(6.17) WAP to display repeated As inverted


n = 3
for i in range(n,0,-1):
for j in range(1, i+1):
print(chr(65), end=" ")
print()

A A A
A A
A

In [1]: #(6.18)
n = 3
x=65
for i in range(n,0,-1):
for j in range(1, i+1):
print(chr(x), end=" ")

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 19/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
x=x+1
print()

A A A
B B
C

In [37]: #(6.19)
n = 3
x=67
for i in range(n,0,-1):
for j in range(1, i+1):
print(chr(x), end=" ")
x=x-1
print()

C C C
B B
A

In [6]: #6.20) WAP to ask the user to enter number of rows and make the following pattern
"""
*
* *
* * *
* *
*
"""
n=int(input("Enter the no. of rows: "))
k=0
for i in range (1,n+1):
k=k+1
for j in range (i,k+i):
print("*",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,i+1):
print("*", end=" ")
print()

Enter the no. of rows: 3


*
* *
* * *
* *
*

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 20/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah

In [2]: #(6.21) WAP to print the same pattern for numbers


n=int(input("Enter the no. of rows: "))
k=0
for i in range (1,n+1):
k=k+1
for j in range (i,k+i):
print(k,end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,i+1):
print(i, end=" ")
print()

Enter the no. of rows: 3


1
2 2
3 3 3
2 2
1

In [22]: #(6.22) WAP to print the same pattern for numbers for alphabets
n=68
for i in range(65,n):
for j in range (65,i+1):
print(chr(i),end=" ")
print()
for i in range(n-2,64,-1):
for j in range (65,1+i):
print(chr(i),end=" ")
print()

A
B B
C C C
B B
A

In [32]: # WAP to print the following pattern-


"""
* * * *
* * * *
* * * *
* * * *
"""
n=int(input("Enter the no. of rows: "))
for i in range(1,n+1):
for i in range(1,n+1):
file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 21/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
print("*",end=" ")
print()

Enter the no. of rows: 4


* * * *
* * * *
* * * *
* * * *

In [27]: # Pascal's triangle


n=int(input("Enter number of rows: "))
k=1
for i in range(1,n+1):
for j in range(k,i+k):
print(j, end=" ")
k+=1
print()

Enter number of rows: 5


1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

In [10]: # WAP to print the following pattern-


"""
* * * *
* *
* *
* * * *
"""
n=int(input("Enter number of rows: "))
for i in range(1,n+1):
if i==1:
for j in range(1,n+1):
print("*", end=" ")
elif i!=1:
print()
else:
print("Error")
print()

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 22/23
12/4/24, 11:13 PM Class X_C_13 Kahan Shah
Enter number of rows: 4
* * * *

In [14]: #(6.7) WAP to display the pattern given below-


a=int(input("Enter number of rows: "))
for i in range(1,a+1):
if i%2!=0:
for j in range(1,i+1):
print(chr(i),end=" ")
else:
for j in range(1,i+1):
print(i,end=" ")
print()

Enter number of rows: 5


1
A B
3 3 3
A B C D
5 5 5 5 5

In [ ]:

file:///Users/KahanPlayzz/Desktop/My Daily work/Math and Science sources/Class X_C_13 Kahan Shah Practical File 2024-25 (Part-1) (1).html 23/23
In [1]: import numpy as np
marks= np.array([50, 60, 85])
print(marks)

[50 60 85]

In [5]: import numpy as np


marks= np.arange(10, 101, 10)
print(marks)

[ 10 20 30 40 50 60 70 80 90 100]

In [9]: #Creating arrays through list


import numpy as np
A=[22,5,2,30,9]
a= np.array(A)
print (a)

[22 5 2 30 9]

In [10]: #Creating arrays through list containing heterogenous data


import numpy as np
A=[22,"I","am","Kahan",7]
a= np.array(A)
print (a)

['22' 'I' 'am' 'Kahan' '7']

In [11]: #OD arrays- single element

import numpy as n
a= n.array(42)
print(a)

42

In [10]: #1D arrays- rows, multiple columns

import numpy as n
a= n.random.randint(20,size=(1,7))
print(a)

[[12 9 4 10 7 3 8]]

In [19]: # Printing random integers


import numpy as n
b= n.random.random()
print(b)

0.9017053547483365

In [16]: #2-D Arrays


import numpy as n
a= n.random.randint(7,size=(2,2))
print(a)

[[4 2]
[0 0]]

In [3]: import numpy as n


a= n.random.randint(420,size=(2,3))
print(a)

[[397 367 357]


[292 226 118]]
In [7]: import numpy as n
a= n.ones((2,3))
print(a)

[[1. 1. 1.]
[1. 1. 1.]]

In [11]: #3-D arrays


import numpy as n
a=n.random.randint(9,size=(3,3))
print(a)

[[7 7 5]
[2 2 1]
[2 7 6]]

In [15]: # Multi dimensional Arrays


import numpy as n
a= n.full((5,7),7)
print(a)

[[7 7 7 7 7 7 7]
[7 7 7 7 7 7 7]
[7 7 7 7 7 7 7]
[7 7 7 7 7 7 7]
[7 7 7 7 7 7 7]]

In [27]: import numpy as n


a = n.random.randomfloat()
print(a)

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_4280\2943293493.py in <module>
1 import numpy as n
----> 2 a = n.random.randomfloat()
3 print(a)

AttributeError: module 'numpy.random' has no attribute 'randomfloat'

In [1]: #Perform addition


import numpy as n
a = n.array([1,2,3,4,5])
b = n.array([6,5,4,3,2])
c= a+b
print(c)

[7 7 7 7 7]

In [2]: #Perform subtraction


import numpy as n
a = n.array([1,2,3,4,5])
b = n.array([6,5,4,3,2])
c= a-b
print(c)

[-5 -3 -1 1 3]

In [3]: #Perform multiplication


import numpy as n
a = n.array([1,2,3,4,5])
b = n.array([6,5,4,3,2])
c= a*b
print(c)
[ 6 10 12 12 10]

In [4]: #Perform division


import numpy as n
a = n.array([1,2,3,4,5])
b = n.array([6,5,4,3,2])
c= a/b
print(c)

[0.16666667 0.4 0.75 1.33333333 2.5 ]

In [5]: #Perform exponentiation


import numpy as n
a = n.array([1,2,3,4,5])
c= a**2
print(c)

[ 1 4 9 16 25]

In [6]: #Perform floor division


import numpy as n
a = n.array([1,2,3,4,5])
b = n.array([6,5,4,3,2])
c= a//b
print(c)

[0 0 0 1 2]

In [7]: #WAP to find remainder for array


import numpy as n
a = n.array([1,2,3,4,5])
b = n.array([6,5,4,3,2])
c= a%b
print(c)

[1 2 3 1 1]

In [19]: #type() function


import numpy as n
a = n.array([1,2,3,4,5])
c= type(a)
print("The type of array is",c)

The type of array is <class 'numpy.ndarray'>

In [12]: #dimension function


import numpy as n
a = n.array([1,2,3,4,5])
c= a.ndim
print("Dimensions:",c)

Dimensions: 1

In [15]: #Shape function


import numpy as n
a = n.array([1,2,3,4,5])
c= a.shape
print("Shape:",c)

Shape: (5,)

In [17]: import numpy as n


a = n.array([1,2,3,4,5])
c= a.size
print("size:",c)
size: 5

In [18]: import numpy as n


a = n.array([1,2,3,4,5])
c= a.dtype
print("data type:",c)

data type: int32

In [20]: import numpy as n


a = n.array([1,2,3,4,5])
c= n.max(a)
print("max value:",c)

max value: 5

In [35]: import numpy as n


a = n.array([[1,2,3,4,5],[10,20,30,40,50]])
c= n.max(a, axis=1)
d= n.max(a, axis=0)
print("Max value in row and column:",c,d)

Max value in both the dimensions: [ 5 50] [10 20 30 40 50]

In [37]: import numpy as n


a = n.array([1,2,3,4,5])
c= n.sort(a)
print("order:",c)

order: [1 2 3 4 5]

In [38]: import numpy as n


a = n.array([1,2,3,4,5])
c= n.sum(a)
print("sum:",c)

sum: 15

In [29]: # calculate average speed from 5 observations


import numpy as n
distance_in_km= n.array([10,20,30,40,50])
time_in_hrs= n.array([5,10,15,20,25])
AverageSpeed_in_km_per_hour= (n.sum(distance_in_km))/(n.sum(time_in_hrs))
print(AverageSpeed_in_km_per_hour, "km/hr")

2.0 km/hr

In [39]: # Python Lab Exercises

In [44]: #(Q.1)
#Sub Part 1
import numpy as n
marks= n.array([45,55,55,44,78,90,60])
m= marks + 2
print(m)

#Sub Part 2
fd= marks//5
print(fd)

#Sub Part 3
mean= n.mean(marks)
median= n.median(marks)
mode= n.argmax(n.bincount(marks))
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)

[47 57 57 46 80 92 62]
[ 9 11 11 8 15 18 12]
Mean: 61.0
Median: 55.0
Mode: 55

In [ ]:
In [ ]: #Matplotlib

In [11]: import matplotlib.pyplot as jarvis


x= [7000,14000,21000,28000,35000,42000,49000]
y= [50,58,67,89,90,98,120]
jarvis.scatter(x,y,color='blue',marker='s')
jarvis.xlabel('No. of vehicles')
jarvis.ylabel('Air pollution levels')
jarvis.title('Air pollution vs no. of cars')
jarvis.show()

In [19]: import matplotlib.pyplot as jarvis


x= ['Mortgage','Loans','Food','Clothing','Subscriptions','Gaming','Healthcare']
y= [500,580,670,890,900,980,1200]
jarvis.bar(x,y)
jarvis.xlabel('Expense categories')
jarvis.ylabel('Expense in dollars')
jarvis.title('Monthly expenses')
jarvis.show()
In [20]: import matplotlib.pyplot as jarvis
x= [7000,14000,21000,28000,35000,42000,49000,56000,63000,70000]
y= [50,58,67,89,90,98,120,145,199,250]
jarvis.plot(x,y,color='blue')
jarvis.xlabel('No. of vehicles')
jarvis.ylabel('Air pollution levels')
jarvis.title('Air pollution vs no. of cars')
jarvis.show()
In [11]: import matplotlib.pyplot as jarvis
import numpy as friday
boys= [100,120,140,160]
girls= [110,130,135,150]
quarters=['Q1','Q2','Q3','Q4']
x=friday.array([0,1,2,3])
jarvis.bar(x,boys,width=0.4,label='Boys')
jarvis.bar(x+0.4,girls,width=0.4,label='Girls')
jarvis.xticks(x+0.2,quarters)
jarvis.xlabel('Quarters')
jarvis.ylabel('No. of books read')
jarvis.title('Comparision of the number of books read by boys and girls over four q
jarvis.legend()
jarvis.show()
In [13]: import matplotlib.pyplot as stat
waiting_time= [5,17,25,34,37,49,50,45,20,36]
time_intervals=[5,15,25,35,45,55]
stat.hist(waiting_time,time_intervals,color='r')
stat.show()

In [4]: import matplotlib.pyplot as plt


students_names= ['Pooja','Neha','Riya','Kavya','Rani','Ravi','Kajal']
students_marks = [45,55,55,44,78,90,60]
plt.bar(students_names,students_marks,color='blue')
plt.xlabel('Names of students')
plt.ylabel('Marks of students')
plt.title('Comparision of marks of 7 students')
plt.show()
In [ ]:
10/24/24, 1:02 PM X-C13_Computer Vision

In [7]: import cv2


import numpy as np
import matplotlib.pyplot as plt
img=cv2.imread("C:/Users/Administrator/Desktop/Visca Barca.jpg")
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title("Visca Barca, Visca Catalunya")
plt.axis("off")
plt.show()

In [ ]:

localhost:8888/nbconvert/html/X-C13_Computer Vision.ipynb?download=false 1/1

You might also like