9,11,12

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 13

EXPT.

NO: 9 (a)
DATE: Implementing real-time/technical applications using File handling -
copy from one file to another
AIM:
To Write a python program to implement File Copying

PROCEDURE:

Step 1: Capture the original path


To begin, capture the path where your file is currently stored.
For example, I stored a CSV file in a folder called AAMEC2(2):
C:\Users\Administrator\Desktop\AAMEC2 (2)\bookk.csv
Where the CSV file name is „products„ and the file extension is csv.
Step 2: Capture the target path
Next, capture the target path where you‟d like to copy the file.
In my case, the file will be copied into a folder called
AAMEC2: C:\Users\Administrator\Desktop \bookk.csv

Step 3: Copy the file in Python using


shutil.copyfile import shutil
original = r'C:\Users\Administrator\Desktop\AAMEC2(2)\bookk.csv'
target = r'C:\Users\Administrator\Desktop\AAMEC2\bookk.csv'
shutil.copyfile(original, target) shutil.copyfile(original, target)
RESULT:
Thus the a python program to implement File Copying was successfully executed
and verified .
EXPT.NO: 9 (b)
DATE: Implementing real-time/technical applications using File
handling word count

AIM:

To Write a python program to implement word count in File operations in python

PROCEDURE:

Step 1: Open and create the txt file with some statements
step 2: To save that file with the extension of txt file
step3 : Now to count the the lenghth of word in a file.
step 4: To display the word count in a target file
PROGRAM:

file =open(r"C:\Users\Administrator\Desktop\count2.txt","rt")
data = file.read()
words = data.split()
print('Number of words in text file :', len(words))

RESULT:
Thus the python program to implement word count in File operations in python was
executed successfully and verified
EXPT.NO: 9 (c)
DATE: Implementing real-time/technical applications using File handling
- Longest word

AIM:

To Write a python program to implement longest word in File operations


PROCEDURE:
Step 1: Open and create the txt file with some statements
step 2: To save that file with the extension of txt file
step3 : Now to count the longest of word in a file.
step 4: To display the longest word in a target file
PROGRAM:

def longest_word(count):
with open(count, 'r') as infile:
words = infile.read().split()
max_len = len(max(words, key=len))
return [word for word in words if len(word) ==
max_len] print(longest_word('count.txt'))

RESULT:

Thus the python program to implement longest word in File operations was
executed successfully verified.
EXPT.NO: 11
DATE: Exploring Pygame tool.

AIM:
To Write a python program to implement pygame
PROCEDURE:
step 1: start the program
step 2: when Key presses, mouse movements, and even joystick movements are
some of the ways in which a user can provide input

step 3: To sets up a control variable for the game loop. To exit the loop and the
game, you set running = False. The game loop starts on line 29.

step 4: starts the event handler, walking through every event currently in the event
queue. If there are no events, then the list is empty, and the handler won’t do
anything.

step 5:check if the current event.type is a KEYDOWN event. If it is, then the
program checks which key was pressed by looking at the event.key attribute. If the
key is the Esc key, indicated by K_ESCAPE, then it exits the game loop by setting
running = False.

step 6: do a similar check for the event type called QUIT. This event only occurs
when the user clicks the window close button. The user may also use any other
operating system action to close the window.

step 7:The window won’t disappear until you press the Esc key, or otherwise trigger
a QUIT event by closing the window.
PROGRAM:
import pygame
from pygame.locals import *
class Square(pygame.sprite.Sprite):
def __init__(self):
super(Square, self).__init__()
self.surf = pygame.Surface((25, 25))
self.surf.fill((0, 200, 255))
self.rect = self.surf.get_rect()
pygame.init()
screen = pygame.display.set_mode((800, 600))
square1 = Square()
square2 = Square()
square3 = Square()
square4 = Square()
gameOn = True
while gameOn:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_BACKSPACE:
gameOn = False
elif event.type == QUIT:
gameOn = False
screen.blit(square1.surf, (40, 40))
screen.blit(square2.surf, (40, 530))
screen.blit(square3.surf, (730, 40))
screen.blit(square4.surf, (730, 530))
pygame.display.flip()

RESULT:
Thus the python program to implement pygame was successfully executed
and verified.
EXPT.NO: 12
DATE: Developing a game activity using Pygame like bouncing ball

AIM:
To Write a python program to implement bouncing balls using pygame tool
PROCEDURE:
Step1: Start the program
Step 2:The pygame.display.set_mode() function returns the surface object for the window.
This function accepts the width and height of the screen as arguments.
Step 3:To set the caption of the window, call the pygame.display.set_caption() function.
opened the image using the pygame.image.load() method and set the ball rectangle area boundary
using
the get_rect() method.
Step 4:The fill() method is used to fill the surface with a background color.
Step 5:pygame flip() method to make all images visible.
Step 6: Stop the program
PROGRAM:
import sys, pygame
pygame.init()
size = width, height = 800, 400
speed = [1, 1]
background = 255, 255, 255
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Bouncing ball")
ball = pygame.image.load("ball.png")
ballrect = ball.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(background)
screen.blit(ball, ballrect)
pygame.display.flip()

RESULT:
Thus the python program to implement bouncing balls using pygame tool
was executed successfully and verified
RESULT:
Thus the python program to implement bouncing balls using pygame tool
was executed successfully and verified

ANJALAI AMMAL MAHALINGAM ENGINEERING COLLEGE

You might also like