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

EXP Py

The document contains examples of file operations in Python like reading and writing to files. It shows how to open a file in read and write mode

Uploaded by

Prasad Kalal
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)
12 views

EXP Py

The document contains examples of file operations in Python like reading and writing to files. It shows how to open a file in read and write mode

Uploaded by

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

EXP-10 A CREATE AND IMPORT MODULE

# python program to create and import module

def greeting(name):

print ("Hello,+name")

import mymodule

mymodule.greeting("Viya")

OUTPUT:

Hello,Viya
EXP-10 B CREATE AND IMPORT PACKAGES

1. CREATE A FOLDER
2. CREATE ANOTHER FOLBER INSIDE PA
3. CREATE TWO FOLDER INSIDE VEXP AS_INIT_PY AND GREETING.PY
4. OPEN IDLE,AND OPEN GREETING.PY AND TYPE A FUNCTION
5. CREATE ANOTHER FOLDER INSIDE PA AS HEY.PY

CODE:

#inside greeting.py

Def great():

Print(‘hello’)

#inside hey.py

from VEXP import greeting

X=greeting.great()

Print(X)

OUTPUT:

Hello

none
#write a python program to implement numpy statistical
functions(mean,median,mode)

#applying mean

import numpy as np

a=np.array([[30,40,50],[80,60,20],[60,40,90]])

print("our array is")

print(a)

print("\n")

print("applying mean function")

print(np.mean(a))

print("\n")

OUTPUT:

our array is

[[30 40 50]

[80 60 20]

[60 40 90]]

applying mean function

52.22222222222222
#applying median

import numpy as np

a=np.array([[30,40,50],[80,60,20],[60,40,90]])

print("our array is")

print(a)

print("\n")

print("applying median() function")

print(np.median(a))

print("\n")

OUTPUT:

our array is

[[30 40 50]

[80 60 20]

[60 40 90]]

applying median() function

50.0
#applying percentile

import numpy as np

a=np.array([[30,40,50],[80,60,20],[60,40,90]])

print("our array is")

print(a)

print("\n")

print("applying percentile() function")

print(np.percentile(a,40))

print("\n")

OUTPUT:

our array is

[[30 40 50]

[80 60 20]

[60 40 90]]

applying percentile() function

42.0
#write a python program to transpose a matrix

X= [[12,7],

[4,5],

[3,8]]

result=[[0,0,0],

[0,0,0]]

for i in range(len(X)):

for j in range(len(X[0])):

result[j] [i] =X[i] [j]

for r in result:

print(r)

OUTPUT:

[12, 4, 3]

[7, 5, 8]
import pandas

start_date="1/1/2023"

end_date="31/12/2023"

list_of_date=pandas.date_range(start=start_date, end=end_date)

df=pandas.DataFrame(list_of_date)

df.columns=["date/time"]

df["8:00"]=100

df["9:00"]=100

df["10:00"]=100

df["11:00"]=100

df["12:00"]=100

df["13:00"]=100

df["14:00"]=100

df["15:00"]=100

df["16:00"]=100

df["17:00"]=100

df.to_csv(

r"centres" + "\\" + vac_postcode + "\\" + vac_center + "\\" + "slots.csv",


index=false,

)
#write a python program to perform file operation

1. Read file
2. Write file

Create file (save as file.txt)

Here it comes,

Ready or not.

Summer’s coming,

And it’s going to be hot!

READ A FILE

f=open(‘file.txt’, ‘r’)

print(f.read())

OUTPUT

Here it comes,

Ready or not.

Summer’s coming,

And it’s going to be hot!

WRITE A FILE

f=open(“file.txt”, “w”)

f.write(“Nature is beautiful”)

f.close()

f=open(“file.txt”, “r”)

print(f.read())

OUTPUT

Nature is beautiful
#write a python program to integrate exception handelling

Try:

Print(x)

Except:

Print(“An exception occurred”)

OUTPUT

An exception occurred

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy