Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

.- •dd,py - C:\ Users\DEll\App0ata\ local\Programs\Python\Python3121.dd.py {3.

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
~

;> IDLE Shell 3.122 □ X


fi le _Edit Shell !lebug Qptions W,ndow J::!elp

Python 3 . 12 . 2 (tags/v3 . 12 . 2 : 6abddd


9 , Feb 6 2024 , 21 : 26 : 36) [MSC v . 1
937 64 bit (AMD64)] on win32
Type "help ", " cop yr igh t ", " credits
" or "license () " for more informat

ion .
>>>
= RESTART : C: /Users/DELL/AppData/L
ocal/Programs/Pyt hon/Python312/dd .
PY
1505 , 1540 , 1575 , 1610 , 1645 , 1680
, 1715 , 1750 , 1785 , 1820 , 1855 , 189
0 , 1925 , 1960 , 1995 , 2030 , 2065 , 2
100 , 2135 , 2170 , 2205 , 2240 , 2275
, 2310 , 2345 , 2380 , 2415 , 2450 , 248
5 , 2520 , 2555 , 2590 , 2625 , 2660 , 2
695 ,
>>> I
,. ' dd,py - C:\ Users\DEll\App0ata\ local\Programs\ Python\ Python3121.dd.py {3.122)' X
file f dit F2m1at Run Qptions W,ndow l:!elp

#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

di ts " or n licen se for mor e 1


() "
1

in.formation .
>>>
== RESTART : C : /u·sers/DELL /AppDa
1

ta/Loc.al/Pro,g rams/ Py thon/ Pytho


n312/dd . py
[ ' Apple ' , ' Banana ' , ' Papaya ,, ,
' Pear : ' ]
>>>
,. 'dd,py - C:\ Users\DEll\App0ata\ local\Programs\ Python\ Python3121.dd.py {3. lU)' X
file fdit fimnat Run Qptions W,ndow J:jelp

#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

Python 3 . 12 . 2 (tags / v3 . 12 . 2 : 6abddd9 , Fe


b 6 2 0 2 4 , 21 : 2 6 : 3 6 ) [MSC v . 19 3 7 6 4 bit
(AMD64)] on win32
Type " help ", " copyright ", " credits " or
" license() " f or more information .
>>>
= RESTART : C : /Users/DELL/AppData/ Local/
Programs/Python/Python312/ dd . py
{1 : 1 , 2 : 4 , 3 : 9 , 4 : 16 , 5 : 25 , 6 : 36 ,
7 : 49 , 8 : 64 , 9 : 81 , 10 : 100 , 11 : 121 ,
12 : 144 ., 13 : 169 , 14 : 196 , 15 : 225}
>>>
,. ' dd,py - C:\Users\DEll\App0ata\ local\Programs\ Python\ Python3121.dd.py {3. lU)' X
file f dit f2m1at Run Qptions W,ndow J:jelp

#WAP to remove duplicate characters of a given string .


n=input ("Enter a string to remove its duplicates :" )
r ="'"
for i in n :
if i net in r :
r+=i
print ("String after removing its duplicates : " , r) ' ' '
I" IDLE Shell 3.12.2 □ X
File Edit Shell Debug Options Window Help

Python 3 . 12 . 2 (t ags/v3 . 12 . 2 : 6abddd9 , Feb 6 2024 , 21 : 26 : 36) [MSC v .


1937 64 bit (AMD64)] on win 32
Type " help ", " copyright " , " credit s " or " l i cense () " for more inf orma
tion .
>>>
= RESTART : C : /U sers/DELL/AppData/Local/Programs/Python / Python312/dd
. py
Enter a string to remove its duplicates : hello
String after removing its duplicat es : helo
>>>
.- ' dd,py - C:\ Users\DEll \App0ata\ local\Programs\ Python\ Python3121.dd.py {3.122)' DI X
file f dit fiinnat Run Qptions W,ndow J:jelp

#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

#Write a python function to calculate t he factorial of a number (a non-negative integer) .


de factorial (n) :
lf n<O :
print (" Factorial is not defined for negative numbers " )
elif n==O or n==l :
return 1
el ,.. :
x=l
f r 1 1~ range (2 , n+l)
x*=i
return x
print (factorial(6 ) )
I' IDLE Shell 3.12.2 D X
file _Edit Shell !;!ebug Qptions Window !:lelp

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 .
11
,
11

>>>
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

#Write a python function that checks whether a String is palindrome or not .


de_ palindrome (s) :
1f s==s[ :: -1] :
print ("The string is in palindrome" )
else :
print ("The string is not in palindrome" )
palindrome( " j t fr s " )
;, 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\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

>>>

You might also like