Professional Documents
Culture Documents
CS Practical XII 2024-25
CS Practical XII 2024-25
122)• DI X
file f dit f2nnat Run Qptions Window J:jelp
#WAP to print those numbers which are divisble by 7 and multiple of 5 , between 1500 ~
for i in range (1500 , 2701) :
1L i%5==0 and i %7==0 :
print ( i , end= " " ) 11
,
11
,
else :
pass
~
#WAP program that accepts a comma separated sequence of words as input and print the unique
#words in sorted form
def sort (s) :
x=s . split( "," )
y=set (x)
z=sorted (y)
print (z)
sort{ " Papaya , Apple , Banana, Apple , Pear : " )
~ IDILE ~hsl J. 122. □ X
fi Ie ~d'"rt 5n E::i.1_1 .Q,61::lug Qptions Vlindow Hel'p
Python 3 . 12 . 2 ( tags/v3 . 12 .2 : 6a
bddd9, Feb 6 2024, 21 : 26 : 36)
[MSC v . 1937 64 bit (Af.1D 64)] on 1 1
win32
Typ e "' help "',
1 co,p yright " ,, ·,, ere 11
in.formation .
>>>
== RESTART : C : /u·sers/DELL /AppDa
1
#WAP to print a dictionary where the keys are numbers between 1 and 15 (Both included)
#and values are square of keys .
d={ l
for i in range (l , 16) :
d[i] =i**2
print (d)
I" IDLE Shell 3.12.2 D X
file f dit Shell Qebug Qptions Window !::!elp
#WAP to accept values from a user i n a t uple . Add a tuple to it and display its
#elements one by o ne . Also display its maximum and minimum value .
tl= ()
n=int (input ("Enter no of elements in tupl e : " ))
for i in range (n ) :
x=int (input ("Enter the elements : " ) )
[
tl=tl+ ( X , )
t 2= (}
m=int (input ("Ent er no of e l eme nts i n tuple : " )}
for i in range (m} :
y=int (input ("Enter the elements : " ) )
t2=t2+( y , )
t = ()
t =tl+t2
for i i r t :
print ("The elements of tuple are" , i )
print ("Maximum value of tuple is : " , max (t}}
print ("Minimum value of tuple is :" , min (t) )
.- IDLE Shell 3.122 DI X
file f dit Shell Qebug Qptions W,ndow J::!elp
Python 3 . 12 . 2 (tags/v3 . 12 . 2 : 6abddd9 , Feb 6 2024 , 21 : 26 : 36) [MSC v . 1937 64 bit (AMD64)] on
win32
Type '' help", "copyright " , "credits " or " license() " for more information .
>>>
= RESTART : C: \Users\DELL\AppData \ Local \ Programs\Python \ Python312\dd . py
Enter no of elements in tuple : 3
Enter the elements : 54
Enter the elements : 84
Enter the elements : 74
Enter no of elements in tuple : 3
Enter the elements : 64
Enter the elements : 49
Enter the elements : 22
The elements of tuple are 54
The elements of tuple are 84
The elements of tuple are 74
The elements of tuple are 64
The elements o f t uple a r e 49
The elements of tuple are 22
Maximum value of tuple is : 84
Minimum value of tuple is : 22
>>>
,. 'dd,py - C:\Users\DEll\App0ata\ local\Programs\ Python\ Python3121.d d.py {3. l U)' DI X
file fdit fiinnat Run Qptions W,ndow J:jelp
#WAF countnow (places ) to find and display those place names in which there are more than five
#of places in a dictionary .
def countnow (places ):
for i in places :
if len (places [i ] ) >S :
print (places[i])
<:!l e :
r::i s
1111
p= {1 : " New Yo rk'' , 2 : " Pune " , 3 : "Banaras" , 4: " Delhi" , 5 : " Patna" }
print ("The Places which have more than 5 letters are :" )
print (countnow (p) )I
.- IDLE Shell 3.122 DI X
file fdit Shell Qebug Qptions W,ndow l::!elp
Python 3 . 12 . 2 (tags/v3 . 12 . 2 : 6abddd9 , Feb 6 2024 , 21 : 26 : 36) [MSC v . 1937 64 bit (AMD64)] on
win32
Type '' help", "copyright " , "credits " or " license() " for more information .
>>>
= RESTART : C: \User s\DELL\AppData\Local\Programs\Python\Python312\dd . py
Enter the no of elements : 4
Enter the elements : 25
Enter the elements : 2
Enter the elements : 4
Enter the elements : 10
[25 , 2, 10 , 4]
>>> I
',, dd.py - C:\Users\D8.l\AppDm\local\Programs\Python\ Python312\dd.py (3.12.2) X
file f dit f2rmat Run Qptions W,ndow J:jelp
>>>
RESTART : C: \Users \DELL\AppData\Local\Programs\ Python\Python3 12 \dd . py
720
>>>
.- ' dd,py - C:\ Users\DEll\App0ata\ local\Programs\ Python\ Python3121.dd.py {3.122)' X
file f dit f2m1at Run Qptions Window l:!elp
Python 3 . 12 . 2 (tags/v3 . 12 . 2 : 6abddd9 , Feb 6 2024 , 21 : 26 : 36) [MSC v . 1937 64 bit (AMD64)] on
win32
Type '' help", "copyright", "credits " or " license() " for more information .
>>>
= RESTART : C: \Use r s\DELL\AppData\Local \ Programs\Python\Python312\dd . py
The string is not in palindrome
>>> I
.- 'dd,py - C:\ Users\DEll\App0ata\ local\Programs\ Python\Python3121.dd.py {3.122)' DI X
file fdit fiinnat Run Qptions W,ndow J:jelp
#WAP to find and display the prime numbers from 2 to N. The value of N should be passed as an ai
def prime (N) :
l = []
for n in range (2, N + 1) :
p = True
fer i in range (2 , int (n** 0 . 5) + 1) :
1.f n% i == 0 :
p= Fal e
biea~:
if p :
l. append (n)
return l
print (nPrirne numbers between 2 and N:" )
for j 11 (prime (45)) :
print (j)
.- IDLE Shell 3.122 ol X
file f dit Shell Qebug Qptions W,ndow l::!elp
Python 3 . 12 . 2 (tags/v3 . 12 . 2 : 6abddd9 , Feb 6 2024 , 21 : 26 : 36) [MSC v . 1937 64 bit (AMD64)] on
win32
Type '' help", "copyright " , "credits " or " license() " for more information .
>>>
= RESTART : C: \Users \DELL\AppData\Local \Programs\Python\ Python312\dd .py - - -
Prime numbers between 2 and N:
2
3
5
7
11
13
17
19
23
29
31
37
41
43
>>> I
',, •dd,py - C:\ Users\0Ell\App0ata\ local\Programs\Python\ Python3121.dd.py {3. tU)• X
file f dit f2m1at Run Qptions W,ndow J:jelp
#Write a function Evensum (numbers} to add those values in the tuple of numbers which are even .
de evens um (n) :
s=O
for i in t :
if i %2= 0 :
s +=i
rf>t 1.Ln s
t= ( 1 , 2 I 3 f 4 f 5 f 6 f 7 f 8 f 9 f 10 }
print ("The sum of even numbers :" , evensum(t) }
.- IDLE Shell 3.122 CJ X
file fdit Shell Qebug Qptions W,ndow l::!elp
Python 3 . 12 . 2 (tags/v3 . 12 . 2 : 6abddd9 , Feb 6 2024 , 21 : 26 : 36) [MSC v . 1937 64 bit (AMD64)] on
win32
Type '' help" , "copyright " , "credits " or " license() " for more information .
>>>
==== RESTART : C: \Users\DELL\AppData\Local\Programs\Python\Python312\dd . py - - -
The sum o f even numbers : 30
>>> I
',, 'dd,py - C:\ Users\DEll\App0ata\ local\Programs\Python\ Python3121.dd.py {3.122)' DI X
file fdit f2m1at Run Qptions Window J:jelp
#Write a Python program to swap the contents of a list if t he next value divisible by 5 .
l= []
n=int (input ("Enter the no of elements :" ))
for i in range (n) :
x=i nt (i nput ("Enter the elements :" ))
l . append(x)
for i in range (len (l) -1 ) :
l l l[i+l]%5==0 :
l[i] , l[i+l]=l[i+l] , l[i]
i+=l
else :
l[i] , l[i+l] =l[i],l[i+l]
print (l)
.- IDLE Shell 3.122 CJ X
file !;dit Shell Qebug Qptions Window J::!elp
Python 3 . 12 . 2 (tags/v3 . 12 . 2 : 6abddd9 , Feb 6 2024 , 21 : 26 : 36) [MSC v . 1937 64 bit (AMD64)] on
win32
Type '' help" , "copyright" , "credits " or " license() " for more information .
>>>
= RESTART : C: \Use r s\DELL\AppDa t a \ Local \ Programs\ Python \ Python312\dd . py
The Places whi ch have more than 5 l e t ters are :
New Yor k
Banaras
>>>