0% found this document useful (0 votes)
22 views18 pages

STD Xi Comp Sci Term 2 Practical Report File 2024-25

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

STD Xi Comp Sci Term 2 Practical Report File 2024-25

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

INDEX

SR PROGRAM DATE PAG TEACHERS


SIGNATUR
. E E&
N NO. REMARKS
O.
01. WAP to find the largest number in a list.

02. WAP to implement Linear Search in a list.

Write Python program to print generate


03.
Fibonacci Series using tuple.

Write Python program to print the largest


04.
even and largest odd number in a list.
Write a Python program Calculate the
05.
Average of Numbers in a Given List.

Write Python Program to search the


06. number of times a particular number
occurs in a list.
Write Python program to sort a list of
tuples in increasing order by the last
07.
element in each tuple.

WAP to check if a given key exists in a


08.
dictionary or not.

WAP to add a key-value pair to a


09.
dictionary.

WAP to find the sum all the items in a


10.
dictionary.

WAP to to multiply all the items in a


11.
dictionary.

12. WAP to remove the given key from a


dictionary.
WAP to Generate the following pattern
using nested loop.
*
13.
**
***
****
*****
WAP to Generate the following pattern
using nested loop.

1
14.
123

1234
12345
WAP to generate the following pattern
using nested loop.
A
15. AB
ABC
ABCD
ABCDE
WAP to input the value of x and n and
print the sum of the following series

16.

WAP to Count and display the number of


vowels, consonants, uppercase,
17.
lowercase characters in string.

PYTHON PROGRAMS
1. WAP to find the largest number in a list.

Code:

a=[]

n=int(input("Enter number of elements:"))

for i in range(1,n+1):

b=int(input("Enter element:"))

a.append(b)

a.sort()

print("Largest element is:",a[n-1])

SAMPLE OUTPUT:

2. WAP to implement Linear Search in a list.

Code:
list_of_elements = [4, 2, 8, 9, 3, 7]

x = int(input("Enter number to search: "))

found = False

for i in range(len(list_of_elements)):

if(list_of_elements[i] == x):

found = True

print("%d found at %dth position"%(x,i))

break

if(found == False):

print("%d is not in list"%x)

SAMPLE OUTPUT:

3. Write Python program to print generate Fibonacci Series


using tuple.

Code:
nterms = 10

n1 = 0

n2 = 1

count = 0

tup=()

# check if the number of terms is valid

if nterms <= 0:

print("Please enter a positive integer")

elif nterms == 1:

print("Fibonacci sequence upto",nterms,":")

print(n1)

else:

print("Fibonacci sequence upto",nterms,":")

while count < nterms:

tup=tup+(n1,)

nth = n1 + n2

# update values

n1 = n2

n2 = nth

count += 1

print (tup)

SAMPLE OUTPUT:

4. Write Python program to print the largest even and largest


odd number in a list.
Code:

n=int(input("Enter the number of elements to be in the list:"))


b=[]
for i in range(0,n):
a=int(input("Element: "))
b.append(a)
c=[]
d=[]
for i in b:
if(i%2==0):
c.append(i)
else:
d.append(i)
c.sort()
d.sort()
count1=0
count2=0
for k in c:
count1=count1+1
for j in d:
count2=count2+1
print("Largest even number:",c[count1-1])
print("Largest odd number",d[count2-1])

SAMPLE OUTPUT:

5. Write a Python program Calculate the Average of Numbers


in a Given List.

Code:
n=int(input("Enter the number of elements to be inserted: "))

a=[]
for i in range(0,n):

elem=int(input("Enter element: "))

a.append(elem)

avg=sum(a)/n

print("Average of elements in the list",round(avg,2))

SAMPLE OUTPUT:

6. Write Python Program to search the number of times a


particular number occurs in a list.

Code:
a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
k=0
num=int(input("Enter the number to be counted:"))
for j in a:
if(j==num):
k=k+1
print("Number of times",num,"appears is",k)

SAMPLE OUTPUT:

7. Write Python program to sort a list of tuples in increasing


order by the last element in each tuple.

Code:

def last(n):

return n[-1]

def sort(tuples):
return sorted(tuples, key=last)

a=input("Enter a list of tuples:")

print("Sorted:")

print(sort(a))

SAMPLE OUTPUT:

8. WAP to check if a given key exists in a dictionary or not.

Code:

d={'A':1,'B':2,'C':3}

key=raw_input("Enter key to check:")

if key in d.keys():

print("Key is present and value of the key is:")

print(d[key])

else:

print("Key isn't present!")

SAMPLE OUTPUT:

9. WAP to add a key-value pair to a dictionary.

Code:

key=int(input("Enter the key (int) to be added:"))

value=int(input("Enter the value for the key to be added:"))

d={}

d.update({key:value})
print("Updated dictionary is:")

print(d)

SAMPLE OUTPUT:

10. WAP to find the sum all the items in a dictionary.

Code:

d={'A':100,'B':540,'C':239}
print("Total sum of values in the dictionary:")
print(sum(d.values()))

SAMPLE OUTPUT:

11. WAP to to multiply all the items in a dictionary.

Code:

d={'A':10,'B':10,'C':239}

tot=1

for i in d:

tot=tot*d[i]
print(tot)

SAMPLE OUTPUT:

12. WAP to remove the given key from a dictionary.

Code:

d = {'a':1,'b':2,'c':3,'d':4}

print("Initial dictionary")

print(d)

key=raw_input("Enter the key to delete(a-d):")

if key in d:

del d[key]

else:

print("Key not found!")

exit(0)

print("Updated dictionary")

print(d)

SAMPLE OUTPUT:

13. WAP to Generate the following pattern using nested loop.

*
**
***
****
*****
Code:

n=int(input("Enter a no"))
for i in range(1, n+1): # outer loop
for j in range(1, i+1): #inner loop
# printing stars
print("*",end="")
# ending line after each row
print("\r")

SAMPLE OUTPUT:

14. WAP to Generate the following pattern using nested loop.


1
12
123
1234
12345

Code:
n=int(input("Enter a no"))
for i in range(1, n+1): # outer loop
for j in range(1, i+1): #inner loop
print(j, end=" ")
# ending line after each row
print("\r")

SAMPLE OUTPUT:

15. WAP to generate the following pattern using nested loop.

A
AB
ABC
ABCD
ABCDE
Code:
n=int(input("Enter the range"))
for i in range(1, n+1): # outer loop
val=65
for j in range(1, i+1): #inner loop
print(chr(val),end=" ")
val=val+1
# ending line after each row
print("\r")

SAMPLE OUTPUT:

16. WAP to input the value of x and n and print the sum of the
following series:
Code:

Series 1:
x = float (input ("Enter value of x :"))

n = int (input ("Enter value of n :"))

s=1

for a in range (1, n + 1) :

s += x**a

print ("Sum of series", s)

Series 2:
x = float (input ("Enter value of x :"))

n = int (input ("Enter value of n :"))

s=1

for a in range (1, n + 1) :

if a%2==0:

s += x**a
else:

s -= x**a

print ("Sum of series", s)

Series 3:
x = float (input ("Enter value of x :"))

n = int (input ("Enter value of n :"))

s=0

for a in range (1, n + 1) :

if a%2==0:

s += (x**a)/a

else:

s -= (x**a)/a

print ("Sum of series", s)

Series 4:
x = float (input ("Enter value of x :"))

n = int (input ("Enter value of n :"))

s=0

fact=1

for a in range (1,n + 1) :

fact=fact*a

if a%2==0:
s += (x**a)/fact

else:

s -= (x**a)/fact

print ("Sum of series", s)

SAMPLE OUTPUT:

17. WAP to Count and display the number of vowels,


consonants, uppercase, lowercase characters in string.

Code:

string = input("Enter Your String : ")

vowels = consonants = uppercase = lowercase = 0

vowels_list = ['a','e','i','o','u',’A’,’E’,’I’,’O’,U’]

for i in string:

if i in vowels_list:

vowels += 1
if i not in vowels_list:

consonants += 1

if i.isupper():

uppercase += 1

if i.islower():

lowercase += 1

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

print("Number of Consonants in this String = ", consonants)

print("Number of Uppercase characters in this String = ",


uppercase)

print("Number of Lowercase characters in this String = ",


lowercase)

SAMPLE OUTPUT:

You might also like