0% found this document useful (0 votes)
19 views5 pages

Python Programming Exp 8 9 11 12

Pspp lab manual

Uploaded by

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

Python Programming Exp 8 9 11 12

Pspp lab manual

Uploaded by

sugimpt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Installing numpy command:


py -m pip install -U numpy –user or pip install numpy
program for nump 1:
import numpy as np
f = [Link](0, 30, 5)
print ("A sequential array with steps of 5:\n", f)
output:
A sequential array with steps of 5:
[ 0 5 10 15 20 25]
Program 2 for numpy:
import numpy as np
a = [Link]([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
print(a)
print([Link])
b = a[1:, 2:]
print(b)
print([Link])
Output:
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
(3, 4)
[[ 7 8]
[11 12]]
(2, 2)
[Link] pandas command:
py -m pip install -U pandas –user or pip install pandas
Program for pandas 1:
import pandas as pd
S = [Link]([11, 28, 72, 3, 5, 8])
print(S)
output:
0 11
1 28
2 72
3 3
4 5
5 8
dtype: int64
Program for pandas 2:
import pandas as pd
import numpy as np
# Creating empty series
ser = [Link]()
print("Pandas Series: ", ser)
# simple array
data = [Link](['g', 'e', 'e', 'k', 's'])
ser = [Link](data)
print("Pandas Series:\n", ser)
output:
Pandas Series: Series([], dtype: object)
Pandas Series:
0 g
1 e
2 e
3 k
4 s
dtype: object

[Link] matplot command:


py -m pip install -U matplot –user or pip install matplot
program for matplot:
# importing the required module
import [Link] as plt
# x axis values
x = [1,2,3]
# corresponding y axis values
y = [2,4,1]
# plotting the points
[Link](x, y)
# naming the x axis
[Link]('x - axis')
# naming the y axis
[Link]('y - axis')
# giving a title to my graph
[Link]('My first graph!')
# function to show the plot
[Link]()
output:
[Link] scipy command:
py -m pip install -U scipy –user or pip install scipy
[Link] for scipy:
from scipy import special
a =special.exp10(3)
print(a)
b =special.exp2(3)
print(b)
c =[Link](90)
print(c)
d =[Link](45)
print(d)
output:
1000.0
8.0
1.0
0.7071067811865475
[Link] for pygame

Step -1 py -m pip install -U pygame –user or pip install pygame


[Link] for screen size:
import pygame

[Link]()
screen =[Link].set_mode([720,1064])
[Link].set_caption('Hello World')
[Link]([0, 0, 0])
[Link]()
[Link](20)
output:

[Link] for rectangle display:


import pygame
[Link]()
screen = [Link].set_mode((400, 300))
done = False
while not done:
for event in [Link]():
if [Link] == [Link]:
done = True
[Link](screen, (0, 125, 255),[Link](60,60, 60, 60))
[Link]()

6. Bouncing ball program


import pygame
# initialize pygame
[Link]()

# define width of screen


width = 1000
# define height of screen
height = 600
screen_res = (width, height)

[Link].set_caption("GFG Bouncing game")


screen = [Link].set_mode(screen_res)

# define colors
red = (255, 0, 0)
black = (0, 0, 0)

# define ball
ball_obj = [Link](
surface=screen, color=red, center=[100, 100], radius=40)
# define speed of ball
# speed = [X direction speed, Y direction speed]
speed = [1, 1]

# game loop
while True:
# event loop
for event in [Link]():
# check if a user wants to exit the game or not
if [Link] == [Link]:
exit()

# fill black color on screen


[Link](black)

# move the ball


# Let center of the ball is (100,100) and the speed is (1,1)
ball_obj = ball_obj.move(speed)
# Now center of the ball is (101,101)
# In this way our wall will move

# if ball goes out of screen then change direction of movement


if ball_obj.left <= 0 or ball_obj.right >= width:
speed[0] = -speed[0]
if ball_obj.top <= 0 or ball_obj.bottom >= height:
speed[1] = -speed[1]

# draw ball at new centers that are obtained after moving ball_obj
[Link](surface=screen, color=red,
center=ball_obj.center, radius=40)

# update screen
[Link]()

You might also like