Professional Documents
Culture Documents
NO NO.
. REMARKS
PYTHON PROGRAMS
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()
1])
SAMPLE OUTPUT:
Code:
list_of_elements = [4, 2, 8, 9, 3, 7] x =
range(len(list_of_elements)):
if(list_of_elements[i] == x):
position"%(x,i))
break
if(found == False):
SAMPLE OUTPUT:
3. WritePython program to print generate Fibonacci Series
using tuple.
Code: nterms =
10 n1 = 0
n2 = 1
count = 0
tup=()
nterms <= 0:
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:
SAMPLE OUTPUT:
SAMPLE OUTPUT:
6. Write Python Program to search the number of times a
particular number occurs in a list.
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):
sort(tuples):
print("Sorted:") print(sort(a))
SAMPLE OUTPUT:
8. WAP to check if a given key exists in a dictionary or not.
Code:
print(d[key]) else:
SAMPLE OUTPUT:
Code:
key=int(input("Enter the key (int) to be added:"))
d={}
d.update({key:value}) print("Updated
SAMPLE OUTPUT:
Code:
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:
d = {'a':1,'b':2,'c':3,'d':4} print("Initial
key to delete(a-d):")
if key in d:
del d[key]
else:
exit(0) print("Updated
dictionary") print(d)
SAMPLE OUTPUT: