Skip to content

Commit 85f80ee

Browse files
authored
mlk
1 parent c441e49 commit 85f80ee

File tree

4 files changed

+33
-49
lines changed

4 files changed

+33
-49
lines changed

programs/14/program.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
# To write a python program simulate bouncing ball in Pygame.
22

33
import pygame
4+
pygame.init()
45

6+
screen = pygame.display.set_mode((800, 600))
7+
pygame.display.set_caption("Bouncing Ball")
58

6-
def main():
7-
pygame.init()
8-
screen = pygame.display.set_mode((800, 600))
9-
pygame.display.set_caption("Bouncing Ball")
10-
ball = pygame.image.load("ball.png")
11-
x = 50
12-
y = 50
13-
x_speed = 5
14-
y_speed = 5
15-
clock = pygame.time.Clock()
16-
while True:
17-
for event in pygame.event.get():
18-
if event.type == pygame.QUIT:
19-
pygame.quit()
20-
quit()
21-
screen.fill((255, 255, 255))
22-
screen.blit(ball, (x, y))
23-
x += x_speed
24-
y += y_speed
25-
if x > screen.get_width() - ball.get_width() or x < 0:
26-
x_speed = -x_speed
27-
if y > screen.get_height() - ball.get_height() or y < 0:
28-
y_speed = -y_speed
29-
pygame.display.update()
30-
clock.tick(60)
9+
x = 30
10+
y = 30
11+
x_speed = 5
12+
y_speed = 5
3113

32-
33-
if __name__ == "__main__":
34-
main()
14+
running = True
15+
while running:
16+
for event in pygame.event.get():
17+
if event.type == pygame.QUIT:
18+
running = False
19+
screen.fill((0, 0, 0))
20+
pygame.draw.circle(screen, (255, 0, 0), (x, y), 30)
21+
x += x_speed
22+
y += y_speed
23+
if x > screen.get_width() - 30 or x < 0:
24+
x_speed *= -1
25+
if y > screen.get_height() - 30 or y < 0:
26+
y_speed *= -1
27+
pygame.display.update()
28+
pygame.quit()
29+
quit()

programs/16/program.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
# from user.
33

44
n = int(input("Enter the number: "))
5-
65
if n % 2 == 0:
7-
print("the number is even")
6+
print("The number is even.")
87
else:
9-
print("the number is odd")
8+
print("The number is odd.")

programs/17/program.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# Write a program to check that a given year is Leap Year or not.
22

33
n = int(input("Enter the year: "))
4-
5-
if n % 4 == 0:
6-
if n % 100 == 0 and n % 400 == 0 or n % 100 != 0:
7-
print("The year is a leap year")
8-
else:
9-
print("The year is not a leap year")
4+
if (n % 4 == 0) and (n % 100 != 0) or (n % 400 == 0):
5+
print("The year is a leap year.")

programs/18/program.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
# Write a Python program to print ‘n terms of Fibonacci series using iteration.
22

3-
n = int(input("Enter the number of terms: "))
4-
5-
63
def fibonacci(n):
7-
a = 0
8-
b = 1
9-
for _ in range(n):
10-
print(a, end=" ")
11-
c = a + b
12-
a = b
13-
b = c
14-
4+
a, b = 0, 1
5+
for i in range(n):
6+
a, b = b, a + b
7+
print(a, end=' ')
8+
print()
159

16-
fibonacci(n)
10+
fibonacci(10)

0 commit comments

Comments
 (0)