Pspp Lab Manual Updated
Pspp Lab Manual Updated
AIM:
Write an algorithm to calculate electricity bill amount with given units consumed
ALGORITHM:
Step 1 : Start
step 11
Step 10 : Total cost = ( (0 * 100) + ( (200 - 100) * 3.5) + ( (400 - 100) * 4.60) +
Step 12 : Stop.
FLOWCHART start
Read Units
Yes NO
Unit<=100
NO
Yes
Amount = Unit<=200
100*0
Yes NO
Amount = (100* 0) + Unit<=500
(Unit – 100)*1.5
Print Amount
Stop
RESULT :
Thus an algorithm and flowchart to calculate the electricity bill was developed
successfully.
EX. NO: 1B RETAIL SHOP BILLING
DATE:
AIM:
ALGORITHM:
Step 1 : Start
Step 8 : Stop
FLOWCHART
Start
Tax=0.18
Rate_of_item
Display Items
Read
Quantities
Cost=Rate_of_item *
quantity+Rate_of_item*quantity+
……………..
Bill Amount=cost+cost*tax
Print BillAmount
Stop
RESULT:
Thus an algorithm and flowchart to calculate the retail shop billing was
developed successfully.
EX.NO: 1C SINE SERIES
DATE:
AIM:
To write an algorithm to evaluate the sine series and develop the flowchart for
the same.
ALGORITHM:
Step 1 : Start
Step 3 : Initialize, n = 1
Step 9 : Stop
FLOWCHART:
Start
Read x,n
x=x*3.14159/180;
t=x;su
m=x;
t=(t*(-1)*x*x)/(2*i*(2*i+1));
sum=sum+t;
Stop
RESULT:
Thus an algorithm and flowchart to calculate the sine series was developed
successfully.
EX.NO: 1D WEIGHT OF MOTOR BIKE
DATE:
AIM:
To write an algorithm to calculate the weight of motor bike and develop the
flowchart for the same.
ALGORITHM:
Step1: Start
RESULT :
Thus, the flow chart and an algorithm for calculating weight of motor bike is developed
Successfully.
EX. NO: 1E WEIGHT OF A STEEL BAR
DATE:
AIM:
ALGORITHM:
Step 1 : Start
Step 6 : Stop
FLOWCHART
Start
Read Diameter D
W =D2/162
Print W
Stop
RESULT :
Thus an algorithm and flowchart to calculate the weight of a steel bar was
developed successfully.
EX.NO: 1F Compute Electrical Current In Three Phase Ac Circuit
DATE:
AIM:
To write an algorithm for electric circuit in three phase AC circuit and develop
the flowchart for the same.
ALGORITHM:
Step 1 : Start
Step 5 : Stop
FLOWCHART
Star
t
Power = (V*I*PF*1.732)
Print(“Power”)
Stop
RESULT :
AIM:
To write a program to exchange the values of two variables.
ALGORITHM:
STEP 1: Start
STEP 4: t=a
STEP 5: a=b
STEP 6: b=t
Read a,b
Print a,b
before swapping
t= a
a=b
b=t
Print a,b
after swapping
Stop
PROGRAM:
print("Before Swapping")
print("a=",a)
print("b=",b)
t=a
a=b
b=t
print("After Swapping")
print("a=",a)
print("b=",b)
RESULT:
Thus, the given program was executed successfully and the output is obtained.
EX.NO: 2B CIRCULATES THEVALUES OF “N” VARIABLES
DATE:
AIM:
To write a python program to circulates the values of “N” variables.
ALGORITHM:
Step 1 : Start
Step 3 : Using slice operator we can continue the step until all the values are
Step 4 : Print B
Step 5 : Stop
FLOWCHART:
PROGRAM:
defcirculate(A,N):
for i in range(1,N+1):
B=A[i:]+A[:i]
print("Circulation ",i,"=",B)
return
A=[91,92,93,94,95]
N=int(input("Enter n:"))
circulate(A,N)
RESULT:
Thus, the given program was executed successfully and the output is obtained.
EX.NO: 2C DISTANCE BETWEEN THE TWO POINTS
DATE:
AIM:
To write a program to find the distance between two points.
ALGORITHM:
step 1: start
step 5: stop
FLOW CHART:
PROGRAM:
Import math
y2=int(input("Enteray2:"))
distance==((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))**0.5
print("Distance= ",distance)
RESULT:
Thus, the given program was executed successfully and the output is obtained.
EX.NO: 3 Programs Using Conditionals and Iterative Statements
DATE:
3A) TO DISPLAY ODD SERIES
AIM:
ALGORITHM :
Step1 : Start
Step4 : Print(i)
Step5 : Stop
PROGRAM:
print(i)
Result :
Thus the program was executed successfully and the output was verified .
Ex.No: 3B NUMBER PATTERN
DATE:
AIM:
To write a python program to print the number pattern.
ALGORITHM:
Step 1 : Start
Step 2 : Read N
Step 3 : i in range(1,N+1),then go to step 4 else go to step 17
Step 4 : k in range (N,i,-1)then go to step 5
Step 5 : print ('' '')
Step 6 : Repeat the step 4 until the condition become false
Step 7 : If the condition is false , then go to step 8
Step 8 : j in range (1,i+1)
Step 9 : print j
Step 10 : Repeat the step 8 until the condition become false
Step 11 : If the condition is false , then goto step 12
Step 12 : i in range (i-1,0,-1)
Step 13 : print i
Step 14 : Repeat the step 12 until the condition become become false
Step 15 :If the condition is false ,then go to step 16
Step 16 :print Number pattern
Step 17 : Stop
PROGRAM:
N =5
For i in range(1,N+1):
for j in range(1,i+1):
print(j, end='')
for i in range(i-1,0,-1):
print(l,end='')
print()
RESULT :
Thus the program was executed successfully and the output was verified .
EX.NO: 3C PRAMID PATTERN
DATE:
AIM:
To write a python program to print the pyramid pattern.
ALGORITHM :
Step 1 : Start
Step 2 : Read n , m
Step 3 : Calculate m = (2*n) - 2
Step 4 : i in range (0 , n)
Step 5 : j in range (0 ,m), then continue the step 6
Step 6 : Calculate m= m - 1
Step 7 : j in range (0 , i+1),then go to step 8 else go to step 10
Step 8 : print(' * ')
Step 9 : Repeat the step 7 until the condition become false
Step 10 : Stop
PROGRAM:
m=(2*n)-2
for I in range(0,n):
for j in range(0,m):
print(end="")
m=m-1
for j in range(0,i+1):
print("*",end='')
print(" ")
RESULT :
Thus the program was executed successfully and the output was
verified.
EX.NO: 4A OPERATIONS OF LISTS
DATE:
AIM:
To perform operations in Materials required for construction of a building using
lists
ALGORITHM:
Step 1: start
# create a list
List_name=['Brick','Cement','Wooden frame','gravel','tiles']
List_name.append(‘wires’)
print('After deleting first two items :', List_name ) # remove from the list
List_name.remove('ironframe')
RESULT :
Thus the program was executed successfully and the output was verified.
EX.NO: 4B OPERATIONS OF TUPLE
DATE:
AIM:
To perform operations in Components of a car using tuple
ALGORITHM:
Step 1: start
Step 2: create a tuple
Step 3: Perform indexing operation
Step 4: Perform slicing operation
Step 5: Perform append or concatenate operation
Step 6: Perform delete operation
Step 7: Perform repeat operation
Step 8: find length of tuple
PROGRAM:
# create a Tuple
Tuple_name=('gear','break','power steering','AC','Tyre')
# repeat tuple
RESULT :
Thus the program was executed successfully and the output was verified.
EX.NO:5A OPERATIONS OF SETS & DICTIONARIES
DATE:
AIM:
PROGRAM:
language1={'C','C++','JAVA'}
language2={'VB','PYTHON','ORACLE','JAVA'}
print(language1)
print(language2)
language1.add('SQL')
print(language1)
language1.remove('SQL')
print(language1)
print(language1 | language2)
print(language2.union(language1))
print(language1 & language2)
print(language1.intersection(language2))
print(language1 -language2)
print(language2.difference(language1))
print(language1 ^ language2)
RESULT :
Thus the program was executed successfully and the output was verified.
EX.NO:5B OPERATIONS OF SETS & DICTIONARIES
DATE:
AIM:
PROGRAM:
print(components)
x = components.copy()
print(x)
x = components.get("Tyre")
print(x)
x = components.items()
print(x)
components.update({"color": "White"})
print(components)
x = components.pop("Brake")
print(x)
print(components)
x = components.setdefault("Brake", "Tyre")
print(x)
print(components)
x = components.values()
print(x)
y=1
thisdict = dict.fromkeys(components, y)
print(thisdict)
x = components.keys()
print(x)
components.clear()
print(components)
RESULT :
Thus the program was executed successfully and the output was verified.
EX.NO: 6 PROGRAMS USING FUNCTIONS
DATE:
AIM:
To write a python program, algorithm and flow chartfor factorial using recursion
function.
ALGORITHM:
Step1: Start
Step2: Read n
Step4: return x
FLOW CHART:
Star
t
Read n
y = fact(n)
Print(y)
Stop
FLOW CHART FOR FUNCTION FACT(N):
fact(n)
No If
Yes
n==0
def fact(n): if n == 0:
return 1
else:
x = n*fact(n-1)
return x
n = int(input("Enter a value:"))
y = fact(n)
print(y)
RESULT:
Thus the program, algorithm and flowchart for factorial using function is made
successfully
EX.NO: 6 PROGRAMS USING FUNCTIONS
DATE:
AIM:
To write a python program to find the largest number ina list using function.
ALGORITHM:
Step1: Start
Step5: Stop
Step3: For i in N
Step6: Stop
FLOWCHART:
Start
Stop
FLOWCHART FOR FUNCTION MAX(N):
max(N)
max = N[0]
False
for i in N
True
If i >
False max
True
max = i
return max
PROGRAM:
def max(N):
max = N[0]
for i in N:
if i > max:
max = i
return max
N = [99, 76, 43, 56, 34]
print("Maximum number = ", max(N))
RESULT:
Thus, the program to find the largest number in a listwas executed successfully.
EX.NO: 6C PROGRAMS USING FUNCTIONS
DATE:
AIM:
To write a python program to find the area of shapes.
ALGORITHM:
Step1: Start
Step6: Stop
Step1: Start
Step2: Input the breadth(b)
Step5: print A
Step1: Start
Step2: Input the side of square
Step4: print A
PROGRAM:
def RectangleArea():
l = int(input("Enter l:"))
b = int(input("Enter b:"))
A=l*b
print("Area of rectangle", A)
def SquareArea():
a = int(input("Enter a:"))
A=a*a
print("Area of square", A)
choice = int(input("Enter a choice:"))
if choice == 1:
RectangleArea()
elif choice == 2:
SquareArea()
else:
print("No shape found")
RectangleArea() SquareArea()
A = l*b A = a*a
Print(A) Print(A)
FLOWCHART:
Start
Read choice
If
elif choice= = 2 No
CallRectangleArea() Yes
Stop
RESULT:
Thus the python program to calculate shapes using function was executed
successfully.
EX.NO: 7 PROGRAMS USING STRINGS
DATE:
AIM:
To write a python program to reverse a given string.
ALGORITHM:
Step1: Start
Step3: Reverse the given string using slice operator andstore it in a variable.
Step4: print the reversed string
Step5: Stop
PROGRAM:
rev_word = word[::-1]
print(rev_word)
RESULT:
DATE:
AIM:
ALGORITHM:
Step1: Start
Step3: Reverse the given string using slice operatorand store it in a variable.
Step4: Check if the reversed string and originalstring are same
Step5: if they are same then print “It is apalindrome”
Step6: else print “Not a palindrome”
Step7: Stop
PROGRAM:
RESULT:
DATE:
ALGORITHM:
Step1: Start
Step3: Ask the user to input the character theywant to get count for
Step4: Initialize a variable named “count”
Step4: For each character in the word provided by the user, check if it
matches the character the user has entered
Step5: if it matches then, increment “count” by one
Step6: Print the variable count
Step7: Stop
PROGRAM:
word = input("Enter a word:")
letter = input("Enter the character :")
count = 0
for char in word:
if char == letter:
count += 1
print("The letter ",letter,"appears",count,"times inthe word")
RESULT:
Thus the program to count the number of characters in a string is executed
successfully andoutput is obtained.
EX.NO:7 PROGRAMS USING STRING
DATE:
ALGORITHM:
Step1: Start
Step2: Input a word from user
Step3: Input the old character that the user want to replace
Step4: Input new character for replacing
Step5: Create an empty string and store it in a variable
Step6: For every character in the word given by user check it is equal to
the old character that the user want to replace.
Step7: If equal then, add the new character to the new string
Step8: Else add the current character to the new string
Step9: Print the new string
Step10: Stop
PROGRAM:
word = input("Enter a word:")
old_char = input("Enter the character you want to replace:")
new_char = input("Enter the new character:")
new_str = ""
for char in word:
if char == old_char:
new_str += new_char
else:
new_str += char
print(new_str)
RESULT:
Thus the program for replacing a character in a string is executed
successfully and output is obtained.
Ex: No:8 PYTHON STANDRAD LIBRARIES
DATE:
A) PANDAS
AIM:
Write a python program to implement python standard library (pandas).
ALGRORITHM:
STEP 1: Start
STEP 2: Using import, we import pandas python package and aliasing pandas as pd
STEP 3: Declare an empty list a and b
STEP 4: Read the number of employee and store it in d
STEP 5: Using for loop,
STEP 5.1: Get the employee id and append it in list a
PROGRAM:
import pandas as pd
a=[ ]
b=[ ]
d=int (input(‘Enter the number of employees:’))
for i in range (0,d):
y=int(input(‘Enter employees id: ‘))
a.append(y)
x=input(‘Enter name of employee:’)
b.append(x)
e={‘Employee_ id’:a,’Employee_ name’:b}
df1= pd.DataFrame(e,columns=[‘Employee_id’,’Employee_name’])
print(df1)
RESULT:
Thus, a python program to implement python standard library (pandas) was executed successfully.
EX.NO.8B NUMPY
DATE:
AIM:
Write a python program to implement python standard library (numpy).
ALGRORITHM:
STEP 1: Start
STEP 2: Using import, we import numpy python package and aliasing numpy as np
STEP 3: Declare array a and b
STEP 4: Add arrays sum (a+b), then
print arrays sum (a+b)
STEP 5: Multiply arrays a and b, then
print array multiplication (a*b)
STEP 6: Using dot ( ) operator multiply arrays a and b, then
print matrix multiplication (a.dot(b))
STEP 7: Divide arrays a and b, then
print array division (a\b)
STEP 8: Stop
PROGRAM:
import numpy as np
a=np.array ([[1,2],
[3,4]])
b=np.array ([[4,3],
[2,1]])
print (“Array sum:\n”,a+b)
print (“Array multiplication:\n”,a*b)
print (“Matrix multiplication:\n”,a.dot(b))
print (“Array division:\n”,a/b)
RESULT:
Thus, python program to implement python standard library (numpy) was executed successfully
EX.NO. 8C MATPLOTLIB
DATE:
AIM:
ALGRORITHM:
STEP 1: Start
STEP 2: Using import, we import matplotlib and pyplot, then we alias pyplot as plt
STEP 3: Using import, we import normal function from numpy.random python package
STEP 4: Using normal( ) function, we declare gaussian_ numbers
STEP 5: Using hist( ) function, we generate the histogram
STEP 6: Using title( ) function, give the title to the graph as Gaussian Histogram
STEP 7: Using xlabel( ) function, we label the x axis as value
STEP 8: Using ylabel( ) function, we label the y axis as Frequency
STEP 9: Using show( ) function, display the histogram
STEP 10: Stop
PROGRAM:
import matplotlib.pyplot as plt
from numpy.random import normal
gaussian_numbers=normal(size=1000)
plt.hist(gaussian_numbers)
plt.title(“Gaussian Histogram”)
plt.xlabel(“Value”)
plt.ylabel(“Frequency”)
plt.show( )
RESULT:
Thus, a python program to implement python standard library (matplotlib) was executed
successfully
EX.NO.8D
DATE: SCIPY
AIM:
Write a python program to implement python standard library (scipy)
ALGORITHM:
STEP 1: Start
STEP 2: Using import, import special function from scipy python package
STEP 3: Using import, we import linaly function from scipy python package
STEP 4: Using import, we import numpy python package and aliasing numpy as np
STEP 5: Using cbrt( ) function, find the cube root of 27 and 64, then store it in cb
STEP 6: Print cb
STEP 7: Using exp( ) function, find the value of 10 to the power 3 and store it in a
STEP 8: Print a
STEP 9: Using exp( ) function, find the value of 2 to the power 3 and store it in b
STEP10: Print b
STEP11: Using sindy ( ) function, find the value of sin 90 and it in c
STEP12: Print c
STEP13: Using cosdg( ) function, find the value of cos 45 and store it in d
STEP14: Print d
STEP15: Declare an array (two_ d_ array)
STEP16: Using det ( ) function, find and print the determinant of the array
STEP17: Using inv ( ) function, find and print the inverse of the array
STEP18: Stop
PROGRAM:
from scipy import special
from scipy import linalg
import numpy as np
cb=special.cbrt([27,64])
print(cb)
a=special.exp10(3)
print(a)
b=special.exp2(3)
print(b)
c=special.sindg(90)
print(c)
d=special.cosdg(45)
print(d)
two_ d_array=np.array([[4,5],[3,2]])
linalg.det(two_d_array)
linalg.inv(two_d_array)
RESULT:
Thus, a python program to implement python standard library (scipy) was executed
successfully.
EX: NO:9 TECHNICAL APPLICATION USINGFILE
DATE: HANDLING
AIM:
Write a python program to copy character from one file to another.
ALGORITHM:
STEP 1: Start
STEP 2: Get the name of Source file in sFile
STEP 4: Using open () function, open the source file (sFile) in reading mode
STEP 7: Again, using open () function, open the target file (tFile) in reading
mode
STEP 8: Using for loop in texts and using write () function, write the characters in
targets file (tFile)
STEP 9: Using close () function, close the target file (tFile)
STEP 10: Print File Copied Successfully
RESULT:
Thus, a python program to implement real-time application to copy characterfrom one file to another
using File Handling was executed successfully
EX: NO:9B WORD COUNT
DATE:
AIM:
Write a python program to implement real-time application to count the words in the text file
using file handling
ALGORITHM:
STEP1: Start
STEP2: Using import, we import counter function from collections python package
STEP3: Define the function word_count ()
STEP4: Get the filename in fname
STEP5: Using with keyword and open () function, open the file as f
STEP6: Using for loop in f,
Step6.1: Split the lines using split () function
Step6.2: Declare num_words=0
Step6.3: Using len () function, store the length of the characters in
num_words
STEP7: Print number of words (num_words)
STEP8: Print the number of each word count in the file(word_count)
STEP9: Stop
Function word_count ()
STEP1: Start
STEP2: Using with keyword and open () function, open the file as f
STEP3: Using counter (), read () and split () functions, we read and split the
characters and count the words respectively
STEP4: Stop
PROGRAM:
from collections import Counter
def word_count(fname):
with open(fname) as f:
return Counter (f.read().split())
fname=input ('Enter the file name:')
with open(fname) as f:
for line in f:
words=line.split()
num_words=0
num_words+=len(words)
print ('Number of words:', num_words)
print ('Number of each word count in the file:\n', word_count(fname))
RESULT:
Thus, a python program to implement real-time application to count the words using file
handling was executed successfully.
EX: NO:9C LONGEST WORD
DATE:
AIM:
Write a python program to implement real-time application to find the longest word in the text
file using file handling.
ALGORITHM:
STEP 1: Start
STEP 2: Define the function longest_words
STEP 3: Get the name of the file in filename
STEP 4: Print longest_words
STEP 5: Stop
Function longest_words ()
STEP 1: Start
STEP 2: Using with keyword, open the file as infile in reading mode
STEP 3: Using read () and split () function, we read and split the character, then
store it in words
STEP 4: Using len () function, find the maximum length of the character
STEP 5: Returns the longest word using for loop and if statement
STEP 6: Stop
PROGRAM:
def longest_words(filename):
words=infile.read().split()
max_len=len(max(words,key=len))
print(longest_words(filename))
RESULT:
Thus, a python program to implement real-time application to find the longest word in the text
file using file handling was executed successfully
Ex: No:10 TECHINICAL APPLICATIONS USINGEXCEPTION HANDLING
DATE:
A).DIVIDE BY ZERO ERROR
AIM:
Write a python program to perform divide by zero error using exception handling.
ALGORITHM:
STEP1: Start
STEP2: Read the inputs x and y
STEP3: Using exception handling perform try block statements
STEP3.1: Perform z=x/y
STEP3.2: print the result of z
STEP4: Display the exception Zero division Error
STEP5: Stop
PROGRAM:
x=int(input("Enter the value of x="))
y=int(input("Enter the value of y="))
try:
z=x/y
print("Result=",z)
except ZeroDivisionError: print("Divide by zero Error")
RESULT:
Thus, the python program was executed successfully.
Ex: No:10B VOTER’S AGE VALIDITY
DATE:
AIM:
Write a python program to perform voter’s age validity using exception handling.
ALGORITHM:
STEP1: Start
STEP2: Call the function voter()
STEP3: Using exception handling perform try block statements
STEP4: Read the input age
STEP5: Check the condition
If(age>=18) then
Print eligible to vote
else
print not eligible to vote
STEP6: If any exception occur perform exception statement
STEP7: Stop
PROGRAM:
def voter():
try:
age=int(input("Enter your age="))
if(age>=18):
print("Eligible to vote")
else:
print("Not eligible to vote")
except ValueError:
print("Age must be valid number")
except IOError:
print("Enter correct value")
except:
print("An error occured")
voter()
RESULT:
Thus, the python program was executed successfully.
Ex: No: 10C STUDENT’S MARK RANGE VALIDATION
DATE:
AIM:
To write a python program to implement real time application to check student’s mark range
validation using Exception Handling.
ALGORITHM:
STEP1: Start
STEP2: In try block, print enter marks obtained in 5 subjects
STEP8: Using if…elf statement, find the range of the average value as given below respectively
(i) 91 10 100
(ii) 81 to 91
(iii) 71 to 81
(iv) 61 to 71
(v) 51 to 61, then
STEP 8.1: Print any one of the statement according to the range of the average value
respectively,
(i) your grade is A
(ii) your grade is B
(iii) your grade is C
S1=int(input())
if S1<0 or S1>100:
S2=int(input())
if S2<0 or S2>100:
S3=int(input())
if S3<0 or S3>100:
S4=int(input())
if S4<0 or S4>100:
S5=int(input())
if S5<0 or S5>100:
finally:
tot=S1+S2+S3+S4+S5
avg=tot/5
else:
ALGORITHM:
STEP1: Start.
STEP2: Set the screen size and caption.
STEP3: Create clock variable.
STEP4: Set x and y radius of ellipse.
STEP5: Starting from degree 0 ending with 360 degrees in increments of 10 degrees
Calculate the (x1, x2) coordinates to find a find a point in the elliptical orbit
STEP6: Converts degree to radians (degree*2*math.pi/360)
STEP7: Draw center circle, ellipse and another smaller circle on the ellipse
STEP8: Refresh the screen every 5 clock ticks
STEP9: Repeats steps 4 to 8 untill user quits the program
STEP10: Stop
PROGRAM:
import pygame
import math
import sys
pygame.init()
screen=pygame.display.set_mode((600,300))
pygame.display.set_caption(“Elliptical orbit”)
clock=pygame.time.Clock()
while (True):
for event in pygame . event.get():
if event.type==pygame.QUIT:
sys.exit()
xradius=250
yradius=100
for degree in range (0,360,10):
x1=int(math.cos(degree*2*math.pi/360)*xradius)+360
x2=int(math.sin(degree*2*math.pi/360)*yradius)+150
screen.fill((0,0,0))
pygame.draw.circle(screen,(255,69,0),[300,150],40)
pygame.draw.ellipse(screen,(255,255,255),[50,50,500,200],1)
pygame.draw.circle(screen,(0,255,0),[x1,y2],20)
pygame.display.flip()
clock.tick(5)
RESULT:
Thus, a python program to simulate the elliptical orbits using pygame was executed
Successfully
Ex: No:12 BOUNCING BALL USING PYGAME
DATE:
BOUNCING BALL
AIM:
Write a python program to develop a game like bouncing ball using pygame tool.
ALGORITHM:
Step1: Start
Step2: Set screen size and background colour
Step3: Set speed of moving ball
Step4: Create a graphical window using set_mode()
Step5: Load the ball image and create a rectangle area covering the image
Step6: when the condition is true,the event is started with a time delay of 2 second
Step7: Move the Ball in specified speed
Step8: If ball hits the edges of the screen reverse the direction
Step9: Use blit() method to copy the ball in the rectangle screen and use flip() method to make
all images visible
Step10: Create an infinite loop and repeat steps 7 and 8 untill user quits the program
Step11: Stop
PROGRAM:
import sys, pygame
pygame.init()
size= width, height=700,250
speed=[1,1]
background=255,255,255
screen=pygame.display.set_mode(size)
pygame.display.set_captain(“Bouncing ball”)
ball=pygame.image.load(“ball.jpg”)
ballrect=ball.get_rect()
while 1:
pygame.time.delay(2)
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)
scren.blit(ball,ballrect)
pygame.diplay.flip()
RESULT:
Thus, a python program to develop a game like bouncing ball using pygame tool was executed
successfully.