0% found this document useful (0 votes)
22 views

Python Notes

This document contains code to demonstrate various Python functions and concepts including: 1. Defining a function to check if a string is a palindrome. 2. Defining a Collatz function that takes a number and prints the steps to reach 1. 3. A function to read and print data from a file. 4. Code to generate a random 3x3 matrix and print it.

Uploaded by

Anusree Kalkaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Python Notes

This document contains code to demonstrate various Python functions and concepts including: 1. Defining a function to check if a string is a palindrome. 2. Defining a Collatz function that takes a number and prints the steps to reach 1. 3. A function to read and print data from a file. 4. Code to generate a random 3x3 matrix and print it.

Uploaded by

Anusree Kalkaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

EXTERIMLAJT-2

lNTro 10N lo THON


unlny yox atala

npul tntey your no me)

nputtnev you oqe"


alhe nputEnter pu oter's name ")

pthe nputtnter youT mothey's name

place
inpul ( "whevc do you Live
unputhwhat avd where do you Study
Stuky
grint (4 T am inamej I am age yeag")

int (Tam
print the child o + tather + "and" + mote

print m om S" 7. place


print( T'm CuLYent studyivg {study
OUTPUT
Ente youY name KOROMAD DALI NIEHITHA

Enter yoUY aqe 18


Erter your ather's name KRISHN iSHDRE

Ertey your mother's name LAKSHMI

hevc do HyDERABAD
yo u
J
Livel

nat
a n d l wheye do you 8tudy'
at JNTUH
St 5Tech
year
KURUM ADDALI NIKHITHA I am 8 yeamg
am

child KISHORE and LAKSHMI


am
the Of KRS HNJA

7omHyderabad
Tm
s BTech at JNTUH
T'm uTently studying yea
n t i g all la pums less lam a quun mube
h u m b e r

int(input("Erter the number"))


punt (The uigt poine numbei3 ess than qiven
numbe
Xtn ange h number):
A07
4oy n Tange (2, X):
i ( 2 y) ==o
break
else
prent (x)
OUTPOT
Enter the number
he ugt 0 pome numbers esS than quve
umber
2
louding
atl
danclos 4 a mumbe
wlethn l apeyect numbeY
shev
.Ai d
the Sm ail k facles u tqual to
Itubey dsell

ber
lnt ( Unput ("Enter the Mumoe")

print ( he dactors onumber


Sum - O

4o7Xn Tange( number)


0
i humber 7 x) = =

print x)
um Sum+int)

Sum number

numberis peject numbes


else
Punt ( numbe is not peryett number"

OUTPUT
Enter the umbe

The actovs
6 pect nurmber
xPERIMENT-3 DeFINING Aup Usincn rowcarOws
Dehint a tolean wlun is-palirdvome

s-palindrome (p):
Tevense PL -
i ENeNse = - P

yeturn toue

else
etun false

p inpuut C' Enter the stzing')

it s paltndrome (P);

print spalirdrome")
else
a palindome ")
print ( r not

oUTPUT

Enter 121
the string
121 Ls palindrome
Wault a functen collatz whaeh does

te dhe ulne p takes oz


A

def collatz(2) ;

CO
whle ( =1):

else
nt(3n)+1)

prnt(x)
C Ct
TetuTn C

he number "),
number unt (nput "Erter
Print Cnm ber)
aint no o steps Colatz Uumbe)

OUTPUT
Enter te numbe 2

1
ho
o Steps
unclion do iad data
em
n

leofaton (Jilename)
de
wrth open (diename " ) s
os tine ind

intluine)

enput Entertne file name


le cpevation (Jile)

OUTPUT

Ente the due name untitled t t

Hello, weluome tothon lab


EXPEFIMENT - 4
wen Ciden mxn
errlitn
amg
impovt numy
e i n t (inpuetEntes he o Nowo")
dlums it ur "Enter the no-0 olums )
ointthee ndes faow colums)
matrixMp ardlom andint1 n34 , Sae-(30,
print (matrt)
OUTPUT
Enter he 3
Etes-the coums 3
Be Ocle 3x3
4 0b5 10$0}
13 70 178]
31L4 32 5U

You might also like