0% found this document useful (0 votes)
19 views15 pages

PRACTICAL 11-20uhbfdfhjdgjm

Practical of class 11

Uploaded by

Nysa Nano
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)
19 views15 pages

PRACTICAL 11-20uhbfdfhjdgjm

Practical of class 11

Uploaded by

Nysa Nano
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/ 15

'''

PRACTICAL-11

============

Input a list of numbers and swap elements at the even location with the

elements at the odd location.

l=eval(input("Enter the elements of a list"))

n=len(l)

print("Elements of Original list=\n",l)

for i in range(0,n,2):

l[i],l[i+1]=l[i+1],l[i]

print("After Interchanging Elements at odd and even positions of list=\n",l)

OUTPUT

Enter the elements of a list[11,22,33,44,55,66,77,88,99,121]

Elements of Original list=

[11, 22, 33, 44, 55, 66, 77, 88, 99, 121]

After Interchanging Elements at odd and even positions of list=

[22, 11, 44, 33, 66, 55, 88, 77, 121, 99]

'''
'''

PRACTICAL-12

============

Create the list['a','bb','ccc',....] that ends with 28 copies of the letter z

char_list=[]

c=1

for i in range(97 ,123):

char_list.append(chr(i)*c)

c=c+1

print("Contents of the list=\n",char_list)

OUTPUT

Contents of the list=

['a', 'bb', 'ccc', 'dddd', 'eeeee', 'ffffff', 'ggggggg', 'hhhhhhhh',

'iiiiiiiii', 'jjjjjjjjjj', 'kkkkkkkkkkk', 'llllllllllll', 'mmmmmmmmmmmmm',

'nnnnnnnnnnnnnn', 'ooooooooooooooo', 'pppppppppppppppp', 'qqqqqqqqqqqqqqqqq',

'rrrrrrrrrrrrrrrrrr', 'sssssssssssssssssss', 'tttttttttttttttttttt',

'uuuuuuuuuuuuuuuuuuuuu', 'vvvvvvvvvvvvvvvvvvvvvv', 'wwwwwwwwwwwwwwwwwwwwwww',

'xxxxxxxxxxxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzzzzzzzzzzzz']

'''
'''

PRACTICAL-13

===========

Write a progarm that reads a number n to display the Fibonacci Series upto the nth term

n=int(input("Enter upto which term do you want to print the Fibonacci Series?"))

t1=0

t2=1

if n==1:

print(t1)

elif n==2:

print(t1,",",t2)

elif n<=0:

print("Invalid entry")

else:

print(t1,",",t2,end=",")

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

tn=t1+t2

t1,t2=t2,tn

print(tn,end=",")

OUTPUT

Enter upto which term do you want to print the Fibonacci Series?26

0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,
75025,

'''
'''

PRACTICAL-14

============

Write a progarm that displays the median of a list of numbers

l=eval(input("Enter the elements of a list"))

n=len(l)

print("Elements of Original list=\n",l)

l.sort()

print("Elements of the list after sorting in ascending order=\n",l)

if n%2==0:

print("Median of list is:",(l[n//2]+l[n//2+1])/2)

else:

print("Median of list is:",(l[n//2]))

OUTPUT-1

Enter the elements of a list[22, 11, 44, 33, 66, 55, 88, 77, 99]

Elements of Original list=

[22, 11, 44, 33, 66, 55, 88, 77, 99]

Elements of the list after sorting in ascending order=

[11, 22, 33, 44, 55, 66, 77, 88, 99]

Median of list is: 55

OUTPUT-2

Enter the elements of a list[22, 11, 44, 33, 66, 55, 88, 77, 121, 99]
Elements of Original list=

[22, 11, 44, 33, 66, 55, 88, 77, 121, 99]

Elements of the list after sorting in ascending order=

[11, 22, 33, 44, 55, 66, 77, 88, 99, 121]

Median of list is: 71.5

'''
'''

PRACTICAL-15

============

Input a tuple of elements, search for a given element in the tuple.

t=eval(input("Enter the elements of a tuple"))

n=len(t)

s=int(input("Enter element to search:"))

p=""

c=0

for j in range(n):

if t[j]==s:

p=p+str(j)+","

c=1

if c==0:

print("Searched Element not in tuple")

else:

print("Searched Element is at position",p," in the tuple")

OUTPUT

Enter the elements of a tuple12,23,52,84,12,35,52,23,75,23

Enter element to search:23

Searched Element is at position 1,7,9, in the tuple

'''
'''

PRACTICAL-16

============

Write aprogram that inputs two tuples seq_a and seq_b and prints True if

every element in seq_a is also an element of seq_b, else prints False

seq_a=eval(input("Enter the elements of first tuple"))

seq_b=eval(input("Enter the elements of second tuple"))

for i in seq_a:

if i not in seq_b:

print("False")

break

else:

print("True")

OUTPUT

Enter the elements of first tuple12,23,52,84,13

Enter the elements of second tuple12,23,52,84,12,35,52,23,75,23

False

'''
'''

PRACTICAL-17

============

Given a dictionary x={'k1':''v1','k2':''v2','k3':''v3'}. Write a program to

A) Create a dictionary with opposite mapping.

B) Print out all the keys in alphabetical order

import json

planets_dictionary={'M':'MERCURY','V':'VENUS','E':'EARTH','A':'MARS','S':'SATURN','J':'JUPITER','U':'U
RANUS','N':'NEPTUNE','P':'PLUTO'}

print("Original dictionary:")

print(json.dumps(planets_dictionary,indent=2))

keys=planets_dictionary.keys()

values=planets_dictionary.values()

planets_dict_reversed=dict(zip(values,keys))

print("Dictionary with opposite mapping:")

print(json.dumps(planets_dict_reversed,indent=2))

keys1=sorted(keys)

print("Keys of the original dictionary sorted alphabetically:")

print(keys1)

OUTPUT

Original dictionary:

"M": "MERCURY",

"V": "VENUS",
"E": "EARTH",

"A": "MARS",

"S": "SATURN",

"J": "JUPITER",

"U": "URANUS",

"N": "NEPTUNE",

"P": "PLUTO"

Dictionary with opposite mapping:

"MERCURY": "M",

"VENUS": "V",

"EARTH": "E",

"MARS": "A",

"SATURN": "S",

"JUPITER": "J",

"URANUS": "U",

"NEPTUNE": "N",

"PLUTO": "P"

Keys of the original dictionary sorted alphabetically:

['A', 'E', 'J', 'M', 'N', 'P', 'S', 'U', 'V']

'''
'''

PRACTICAL-18

===========

Create a dictionary with the roll number, name and marks of n students in a class and display the

names of students who have scored marks above 74.

import json

stu_dict={}

n=int(input("Enter how many students:"))

for i in range(n):

rn=int(input("Enter roll no of student:"))

nm=input("Enter name of student:")

mk=int(input("Enter marks of student:"))

stu_dict[rn]=[nm,mk]

print("Details of all students:")

print(json.dumps(stu_dict,indent=2))

stu_distiction={}

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

if stu_dict[j][1]>=75:

stu_distiction[j]=stu_dict[j]

print("Details of students scoring more than 74 marks:")

print(json.dumps(stu_distiction,indent=2))

OUTPUT

Enter how many students:6

Enter roll no of student:1

Enter name of student:Anil


Enter marks of student:79

Enter roll no of student:2

Enter name of student:Bishakha

Enter marks of student:65

Enter roll no of student:3

Enter name of student:Chetan

Enter marks of student:71

Enter roll no of student:4

Enter name of student:Darsana

Enter marks of student:89

Enter roll no of student:5

Enter name of student:Fahim

Enter marks of student:78

Enter roll no of student:6

Enter name of student:Naina

Enter marks of student:58

Details of all students:

"1": [

"Anil",

79

],

"2": [

"Bishakha",

65

],

"3": [
"Chetan",

71

],

"4": [

"Darsana",

89

],

"5": [

"Fahim",

78

],

"6": [

"Naina",

58

Details of students scoring more than 74 marks:

"1": [

"Anil",

79

],

"4": [

"Darsana",

89

],

"5": [
"Fahim",

78

'''
'''

PRACTICAL-19

==============

Write a program to generate an otp of n digits

import random

n=int(input("How many digit OTP you want to generate"))

a=pow(10,n-1)

b=pow(10,n)-1

print("The",n,"digit OTP is",random.randint(a,b))

OUTPUT1

How many digit OTP you want to generate6

The 6 digit OTP is 452738

OUTPUT2

How many digit OTP you want to generate4

The 4 digit OTP is 8433

'''
'''

PRACTICAL-20

============

import math

a=int(input("Enter one number:"))

b=int(input("Enter another number:"))

ans=math.pow(a,3) + math.pow(b,3) + 3*math.pow(a,2)*b + 3*math.pow(b,2)*a

print("Answer =",ans)

OUTPUT

Enter one number:10

Enter another number:6

Answer = 4096.0

'''

You might also like