Skip to content

Commit ee26072

Browse files
authored
Some Project files
1 parent bec8d01 commit ee26072

File tree

7 files changed

+316
-0
lines changed

7 files changed

+316
-0
lines changed

2_Player_PongGame.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import sys
2+
import pygame
3+
import random
4+
import time
5+
6+
print('\n\tWelCome to Dou Pong Game by DarBar Bros')
7+
print('\n\t\tPlayer Blue: Up and Down keys')
8+
print('\t\tPlayer Orange: Z and X keys')
9+
print("\n\nPress Q/q for Quit")
10+
11+
pygame.init()
12+
13+
time.sleep(5)
14+
clock = pygame.time.Clock()
15+
16+
score1 = 0
17+
score2 = 0
18+
player_speed = 0
19+
20+
screen_width = 800
21+
screen_height = 600
22+
screen = pygame.display.set_mode((screen_width, screen_height))
23+
pygame.display.set_caption("Pong game")
24+
25+
ball = pygame.Rect(screen_width / 2 - 8.5, screen_height / 2 - 8.5, 17, 17)
26+
player = pygame.Rect(screen_width - 20, screen_height / 2 - 70, 10, 100)
27+
opponent = pygame.Rect(10, screen_height / 2 - 70, 10, 100)
28+
bg_color = pygame.Color("grey20")
29+
light_grey = pygame.Color(200, 200, 200)
30+
ball_speed_x = 8 * random.choice((1, -1))
31+
ball_speed_y = 8 * random.choice((1, -1))
32+
33+
opponent_speed = 0
34+
35+
36+
def ball_animation():
37+
global ball_speed_x, ball_speed_y
38+
ball.x += ball_speed_x
39+
ball.y += ball_speed_y
40+
41+
if ball.top <= 0 or ball.bottom >= screen_height:
42+
ball_speed_y *= -1
43+
if ball.left <= 0:
44+
ball_restart()
45+
score1 + 1
46+
if ball.right >= screen_width:
47+
ball_restart()
48+
score2 + 1
49+
if ball.colliderect(player) or ball.colliderect(opponent):
50+
ball_speed_x *= -1
51+
52+
53+
def ball_restart():
54+
global ball_speed_y, ball_speed_x
55+
ball.center = (screen_width / 2, screen_height / 2)
56+
ball_speed_y *= random.choice((1, -1))
57+
ball_speed_x *= random.choice((1, -1))
58+
59+
60+
while True:
61+
for event in pygame.event.get():
62+
if event.type == pygame.QUIT:
63+
print("\n\tThank You!! :-)")
64+
pygame.quit()
65+
sys.exit()
66+
if event.type == pygame.KEYDOWN:
67+
if event.key == pygame.K_q:
68+
print("\n\tThank You!! :-)")
69+
pygame.quit()
70+
sys.exit()
71+
if event.type == pygame.KEYDOWN:
72+
if event.key == pygame.K_DOWN:
73+
player_speed += 7
74+
if event.type == pygame.KEYDOWN:
75+
if event.key == pygame.K_UP:
76+
player_speed -= 7
77+
if event.type == pygame.KEYUP:
78+
if event.key == pygame.K_DOWN:
79+
player_speed -= 7
80+
if event.type == pygame.KEYUP:
81+
if event.key == pygame.K_UP:
82+
player_speed += 7
83+
if event.type == pygame.KEYDOWN:
84+
if event.key == pygame.K_DOWN:
85+
player_speed += 7
86+
if event.type == pygame.KEYDOWN:
87+
if event.key == pygame.K_UP:
88+
player_speed -= 7
89+
if event.type == pygame.KEYUP:
90+
if event.key == pygame.K_DOWN:
91+
player_speed -= 7
92+
if event.type == pygame.KEYUP:
93+
if event.key == pygame.K_UP:
94+
player_speed += 7
95+
96+
if event.type == pygame.KEYDOWN:
97+
if event.key == pygame.K_x:
98+
opponent_speed += 7
99+
if event.type == pygame.KEYDOWN:
100+
if event.key == pygame.K_z:
101+
opponent_speed -= 7
102+
if event.type == pygame.KEYUP:
103+
if event.key == pygame.K_x:
104+
opponent_speed -= 7
105+
if event.type == pygame.KEYUP:
106+
if event.key == pygame.K_z:
107+
opponent_speed += 7
108+
109+
screen.fill(bg_color)
110+
pygame.draw.rect(screen, ("royalblue"), player)
111+
pygame.draw.rect(screen, (255, 85, 0), opponent)
112+
pygame.draw.ellipse(screen, light_grey, ball)
113+
pygame.draw.aaline(screen, light_grey, (screen_width / 2, 0),
114+
(screen_width / 2, screen_height))
115+
116+
ball_animation()
117+
player.y += player_speed
118+
if player.top <= 0:
119+
player.top = 0
120+
if player.bottom >= screen_height:
121+
player.bottom = screen_height
122+
opponent.y += opponent_speed
123+
if opponent.top <= 0:
124+
opponent.top = 0
125+
if opponent.bottom >= screen_height:
126+
opponent.bottom = screen_height
127+
pygame.display.flip()
128+
clock.tick(60)

Fibonacci_Series.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
a=int(input("Enter a number : "))
2+
x = 0
3+
y = 1
4+
z = 0
5+
while(z <= a):
6+
print(z)
7+
x=y
8+
y=z
9+
z=x+y

LeapYearFinder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
year = int(input("\nEnter year here : "))
2+
if year % 4 == 0:
3+
print("\nHurray! its leap year")
4+
if year % 4 == 3:
5+
print(f"\nNext year is leap year -- {year+1}")
6+
if year % 4 == 2:
7+
print(f"\nAfter 2 years is leap year -- {year+2}")
8+
if year%4==1:
9+
print(f"\nOps!!, Pervious year was leap year -- {year-1}")

Password_Generator.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import random
2+
3+
if __name__ == "__main__":
4+
s1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','o','p','q','r','s','t','u','v','w','x','y','z']
5+
s2 = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
6+
s3 = ['1','2','3','4','5','6','7','8','9','0']
7+
s4 = ['!','@','#','$','%','^','&','*','(',')','_','+','{','}','|','[',']','"',';','<','>','?','/',',']
8+
9+
passLen = int(input("Enter Your password lenght: "))
10+
s = []
11+
s.extend(s1)
12+
s.extend(s2)
13+
s.extend(s3)
14+
s.extend(s4)
15+
a =0
16+
print("Choose any one of the 5 passwords given below!")
17+
print("")
18+
while a<5:
19+
random.shuffle(s)
20+
print("\t","".join(s[0:passLen]))
21+
a=a+1

Single_Player_PongGame.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import sys
2+
import pygame
3+
import random
4+
5+
6+
from pygame import time
7+
8+
pygame.init()
9+
10+
clock = pygame.time.Clock()
11+
12+
print("Press Q/q for quit/end the game")
13+
time.wait(3000)
14+
screen_width = 800
15+
screen_height = 600
16+
screen = pygame.display.set_mode((screen_width, screen_height))
17+
pygame.display.set_caption("Pong game")
18+
19+
ball = pygame.Rect(screen_width / 2 - 8.5, screen_height / 2 - 8.5, 17, 17)
20+
player = pygame.Rect(screen_width - 20, screen_height / 2 - 70, 10, 100)
21+
opponent = pygame.Rect(10, screen_height / 2 - 70, 10, 100)
22+
bg_color = pygame.Color("grey20")
23+
light_grey = pygame.Color(200, 200, 200)
24+
ball_speed_x = 7 * random.choice((1, -1))
25+
ball_speed_y = 7 * random.choice((1, -1))
26+
player_speed = 0
27+
opponent_speed = 10
28+
29+
30+
def ball_animation():
31+
global ball_speed_x, ball_speed_y
32+
ball.x += ball_speed_x
33+
ball.y += ball_speed_y
34+
35+
if ball.top <= 0 or ball.bottom >= screen_height:
36+
ball_speed_y *= -1
37+
if ball.left <= 0 or ball.right >= screen_width:
38+
ball_restart()
39+
if ball.colliderect(player) or ball.colliderect(opponent):
40+
ball_speed_x *= -1
41+
42+
43+
def player_animation():
44+
player.y += player_speed
45+
if player.top <= 0:
46+
player.top = 0
47+
if player.bottom >= screen_height:
48+
player.bottom = screen_height
49+
50+
51+
def opponent_animation():
52+
if opponent.top < ball.y:
53+
opponent.top += opponent_speed
54+
if opponent.bottom > ball.y:
55+
opponent.bottom -= opponent_speed - 2
56+
opponent.bottom = opponent.bottom - 5
57+
if opponent.top <= 0:
58+
opponent.top = 0
59+
if opponent.bottom > 600:
60+
opponent.bottom = 600
61+
62+
63+
def ball_restart():
64+
global ball_speed_y, ball_speed_x
65+
ball.center = (screen_width / 2, screen_height / 2)
66+
ball_speed_y *= random.choice((1, -1))
67+
ball_speed_x *= random.choice((1, -1))
68+
69+
70+
while True:
71+
for event in pygame.event.get():
72+
if event.type == pygame.QUIT:
73+
print("\n\tThank You!! :-)")
74+
pygame.quit()
75+
sys.exit()
76+
if event.type == pygame.KEYDOWN:
77+
if event.key == pygame.K_q:
78+
print("\n\tThank You!! :-)")
79+
pygame.quit()
80+
sys.exit()
81+
if event.type == pygame.KEYDOWN:
82+
if event.key == pygame.K_DOWN:
83+
player_speed += 7
84+
if event.type == pygame.KEYDOWN:
85+
if event.key == pygame.K_UP:
86+
player_speed -= 7
87+
if event.type == pygame.KEYUP:
88+
if event.key == pygame.K_DOWN:
89+
player_speed -= 7
90+
if event.type == pygame.KEYUP:
91+
if event.key == pygame.K_UP:
92+
player_speed += 7
93+
if event.type == pygame.KEYDOWN:
94+
if event.key == pygame.K_DOWN:
95+
player_speed += 7
96+
if event.type == pygame.KEYDOWN:
97+
if event.key == pygame.K_UP:
98+
player_speed -= 7
99+
if event.type == pygame.KEYUP:
100+
if event.key == pygame.K_DOWN:
101+
player_speed -= 7
102+
if event.type == pygame.KEYUP:
103+
if event.key == pygame.K_UP:
104+
player_speed += 7
105+
106+
screen.fill(bg_color)
107+
pygame.draw.rect(screen, "royalblue", player)
108+
pygame.draw.rect(screen, (255, 85, 0), opponent)
109+
pygame.draw.ellipse(screen, light_grey, ball)
110+
pygame.draw.aaline(screen, light_grey, (screen_width / 2, 0),
111+
(screen_width / 2, screen_height))
112+
113+
ball_animation()
114+
player_animation()
115+
opponent_animation()
116+
117+
pygame.display.flip()
118+
clock.tick(60)

Temperature_converter.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
print("\n\tWelcome to Temperature Converter\n")
2+
print("Enter value which you want to convert : ")
3+
value = float(input())
4+
print(" Enter 1 for Celsius to Fahrenheit converter....")
5+
print(" Enter 2 for Fahrenheit to Celsius converter....")
6+
ans = int(input("\nEnter your value here... "))
7+
if ans == 1:
8+
value = (value * +1.8 + 32)
9+
print(f"\nYour conversion is here.. {value}°F")
10+
elif ans == 2:
11+
value = ((value - 32) * (5 / 9))
12+
print(f"\nYour conversion is here.. {(value)}°C")
13+
else:
14+
print("\nInvalid Input")

TimeClock.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from tkinter import *
2+
from tkinter.ttk import *
3+
from time import strftime
4+
5+
root = Tk()
6+
root.title("Clock")
7+
8+
def time():
9+
string = strftime("%H:%M:%S %p")
10+
label.config(text=string)
11+
label.after(100,time)
12+
13+
label = Label(root, font=("ds-digital", 85), background="#000", foreground="#0ff")
14+
label.pack(anchor='center')
15+
16+
time()
17+
mainloop()

0 commit comments

Comments
 (0)