STD Xi Comp Sci Term 2 Practical Report File 2024-25
STD Xi Comp Sci Term 2 Practical Report File 2024-25
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.
PYTHON PROGRAMS
1. WAP to find the largest number in a list.
Code:
a=[]
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
a.sort()
SAMPLE OUTPUT:
Code:
list_of_elements = [4, 2, 8, 9, 3, 7]
found = False
for i in range(len(list_of_elements)):
if(list_of_elements[i] == x):
found = True
break
if(found == False):
SAMPLE OUTPUT:
Code:
nterms = 10
n1 = 0
n2 = 1
count = 0
tup=()
if nterms <= 0:
elif nterms == 1:
print(n1)
else:
tup=tup+(n1,)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
print (tup)
SAMPLE OUTPUT:
SAMPLE OUTPUT:
Code:
n=int(input("Enter the number of elements to be inserted: "))
a=[]
for i in range(0,n):
a.append(elem)
avg=sum(a)/n
SAMPLE OUTPUT:
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:
Code:
def last(n):
return n[-1]
def sort(tuples):
return sorted(tuples, key=last)
print("Sorted:")
print(sort(a))
SAMPLE OUTPUT:
Code:
d={'A':1,'B':2,'C':3}
if key in d.keys():
print(d[key])
else:
SAMPLE OUTPUT:
Code:
d={}
d.update({key:value})
print("Updated dictionary is:")
print(d)
SAMPLE OUTPUT:
Code:
d={'A':100,'B':540,'C':239}
print("Total sum of values in the dictionary:")
print(sum(d.values()))
SAMPLE OUTPUT:
Code:
d={'A':10,'B':10,'C':239}
tot=1
for i in d:
tot=tot*d[i]
print(tot)
SAMPLE OUTPUT:
Code:
d = {'a':1,'b':2,'c':3,'d':4}
print("Initial dictionary")
print(d)
if key in d:
del d[key]
else:
exit(0)
print("Updated dictionary")
print(d)
SAMPLE OUTPUT:
*
**
***
****
*****
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:
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:
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 :"))
s=1
s += x**a
Series 2:
x = float (input ("Enter value of x :"))
s=1
if a%2==0:
s += x**a
else:
s -= x**a
Series 3:
x = float (input ("Enter value of x :"))
s=0
if a%2==0:
s += (x**a)/a
else:
s -= (x**a)/a
Series 4:
x = float (input ("Enter value of x :"))
s=0
fact=1
fact=fact*a
if a%2==0:
s += (x**a)/fact
else:
s -= (x**a)/fact
SAMPLE OUTPUT:
Code:
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
SAMPLE OUTPUT: