Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit ccb292a

Browse files
authored
Merge branch 'main' into battleship
2 parents 61355c2 + 238cf69 commit ccb292a

9 files changed

Lines changed: 556 additions & 82 deletions

File tree

README.md

Lines changed: 80 additions & 80 deletions
Large diffs are not rendered by default.

projects/Calculator/main.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def multiplication():
2525
def division():
2626
n1 = float(input("Enter first number: "))
2727
n2 = float(input("Enter second number: "))
28+
if n2 == 0:
29+
print("Invalid entry")
30+
return "Invalid entry"
31+
print(n1 / n2)
2832

2933
return n1 / n2
3034

@@ -34,13 +38,83 @@ def average():
3438
return sum(nums) / len(nums)
3539

3640

41+
def factorial(num):
42+
answer = 1
43+
for i in range(num):
44+
answer *= i + 1
45+
return answer
46+
47+
48+
def complexarithmetic():
49+
print("Enter '1' for complex addition")
50+
print("Enter '2' for complex substraction")
51+
print("Enter '3' for complex multiplication")
52+
print("Enter '4' for complex division")
53+
choice = input("enter your choice")
54+
if choice == "1":
55+
nums = list(map(int, input("Enter all numbers seperated by space: ").split()))
56+
real_sum = 0
57+
imag_sum = 0
58+
for i in range(0, len(nums) - 1, 2):
59+
real_sum += nums[i]
60+
for i in range(2, len(nums) - 1, 2):
61+
imag_sum += nums[i]
62+
imag_sum += nums[-1]
63+
return f"{real_sum}+ i{imag_sum}"
64+
65+
elif choice == "2":
66+
nums = list(map(int, input("Enter all numbers seperated by space: ").split()))
67+
real_sub = nums[0]
68+
imag_sub = nums[1]
69+
for i in range(2, len(nums) - 1, 2):
70+
real_sub -= nums[i]
71+
for i in range(3, len(nums) - 1, 2):
72+
imag_sub -= nums[i]
73+
imag_sub -= nums[-1]
74+
return f"{real_sub}+ i{imag_sub}"
75+
76+
elif choice == "3":
77+
nums = list(
78+
map(
79+
int,
80+
input(
81+
"Enter all numbers seperated by space maximum 4 elements: "
82+
).split(),
83+
)
84+
)
85+
real = nums[0] * nums[2] - nums[1] * nums[3]
86+
imag = nums[0] * nums[3] + nums[2] * nums[1]
87+
return f"{real}+ i{imag}"
88+
89+
elif choice == "4":
90+
nums = list(
91+
map(
92+
int,
93+
input(
94+
"Enter all numbers seperated by space maximum 4 elements: "
95+
).split(),
96+
)
97+
)
98+
real = (nums[0] * nums[2] + nums[1] * nums[3]) / (nums[2] ** 2 + nums[3] ** 2)
99+
imag = (nums[1] * nums[2] - nums[0] * nums[3]) / (nums[2] ** 2 + nums[3] ** 2)
100+
return f"{real}+ i{imag}"
101+
102+
103+
def binomail(num):
104+
result = factorial(num[0]) / (factorial(num[1]) * factorial(num[0] - num[1]))
105+
return result
106+
107+
37108
c = 0
38109
while c != "-1":
39110
print("Enter '1' for addition")
40111
print("Enter '2' for subtraction")
41112
print("Enter '3' for multiplication")
42113
print("Enter '4' for division")
43114
print("Enter '5' for average")
115+
print("Enter '6' for factorial")
116+
print("Enter '7' for complex arithmetic")
117+
print("ENter '8' for binomial")
44118
print("Enter '-1' to exit.\n")
45119

46120
c = input("Your choice is: ")
@@ -69,6 +143,8 @@ def average():
69143
elif c == "4":
70144
res = division()
71145
os.system("cls")
146+
if res == "Invalid entry":
147+
continue
72148
print(f"The answer is {res}")
73149
time.sleep(2)
74150
os.system("cls")
@@ -80,6 +156,35 @@ def average():
80156
time.sleep(2)
81157
os.system("cls")
82158

159+
elif c == "6":
160+
num = int(input("enter the number: "))
161+
if num < 0:
162+
print("Invalid entry")
163+
continue
164+
res = factorial(num)
165+
os.system("cls")
166+
print(f"The answer is {res}")
167+
time.sleep(2)
168+
os.system("cls")
169+
170+
elif c == "7":
171+
os.system("cls")
172+
print(complexarithmetic())
173+
time.sleep(2)
174+
os.system("cls")
175+
176+
elif c == "8":
177+
os.system("cls")
178+
num = list(map(int, input("Enter the number seperated by space").split()))
179+
if num[0] < num[1]:
180+
print("Invalid entry")
181+
continue
182+
res = binomail(num)
183+
os.system("cls")
184+
print(f"The answer is {res}")
185+
time.sleep(2)
186+
os.system("cls")
187+
83188
elif c == "-1":
84189
os.system("cls")
85190
print("Thank you for using the calculator!")

projects/HandCricket/Readme.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
# Hand Cricket Game
3+
4+
## Overview
5+
This is a simple command-line-based Hand Cricket game implemented in Python. It allows you to play cricket against a computer opponent. You can either choose to bat first or bowl first and select the difficulty level of the computer opponent.
6+
7+
## Features
8+
- User-friendly command-line interface.
9+
- Choose the number of overs (1-10) for the game.
10+
- Choose to bat or bowl first.
11+
- Three difficulty levels for the computer opponent (Easy, Medium, Hard).
12+
- Realistic cricket scoring and gameplay.
13+
14+
15+
### Installation
16+
1. Clone this repository to your local machine:
17+
18+
```bash
19+
git clone https://github.com/your-username/hand-cricket-game.git
20+
```
21+
22+
2. Navigate to the project directory:
23+
24+
```bash
25+
cd hand-cricket-game
26+
```
27+
28+
### Usage
29+
1. Open your terminal or command prompt.
30+
31+
2. Navigate to the project directory.
32+
33+
3. Run the game using Python:
34+
35+
```bash
36+
python hand_cricket.py
37+
```
38+
39+
4. Follow the on-screen instructions to play the game.
40+
41+
## Game Rules
42+
- You can choose to bat or bowl first.
43+
- While batting, enter your shot choice (1-6) for each ball.
44+
- While bowling, enter your delivery choice (1-6) for each ball.
45+
- If your choice matches the computer's, you are out.
46+
- Score as many runs as you can while batting.
47+
- Try to dismiss the computer's batsmen while bowling.
48+
- The game ends after the specified number of overs.
49+
50+
## Contributing
51+
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
52+
1. Fork the project.
53+
2. Create a new branch for your feature or bug fix.
54+
3. Make your changes and commit them.
55+
4. Push your changes to your fork.
56+
5. Submit a pull request to the main repository.
57+
58+
59+
## Acknowledgments
60+
- This game was inspired by the popular hand cricket game played by many cricket enthusiasts.
61+
- Special thanks to the Python community for providing helpful libraries and resources.

projects/QRCode-Generator/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
colorama==0.4.5
22
comtypes==1.1.11
3-
Pillow==9.3.0
3+
Pillow==10.0.1
44
pypiwin32==223
55
pyttsx3==2.90
66
pywin32==304

projects/QuickWordCloud/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mypy-extensions==0.4.3
1111
numpy==1.23.3
1212
packaging==21.3
1313
pathspec==0.10.1
14-
Pillow==9.3.0
14+
Pillow==10.0.1
1515
platformdirs==2.5.2
1616
pluggy==1.0.0
1717
pyparsing==3.0.9
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
from flask import Flask, request, redirect, render_template, send_file
2+
import zipfile
3+
import numpy as np
4+
import smtplib
5+
import concurrent.futures # for multithreading compilation
6+
7+
# import sys
8+
# import re
9+
from pytube import YouTube # downloading the mp4 file
10+
from pydub import AudioSegment # creating small snippets
11+
from pydub.utils import make_chunks # making small chunks out of it
12+
import os
13+
from email.mime.multipart import MIMEMultipart # Emailing the output to the user
14+
from email.mime.base import MIMEBase
15+
from email.utils import COMMASPACE, formatdate
16+
from email import encoders # Encoding the attachment
17+
from zipfile import ZipFile
18+
from youtube_search import (
19+
YoutubeSearch,
20+
) # Bypassing the Youtube API with the another API
21+
import pandas as pd
22+
23+
app = Flask(__name__)
24+
25+
26+
@app.route("/", methods=["GET", "POST"])
27+
def index():
28+
if request.method == "POST":
29+
singer = request.form["singer"]
30+
Number_vid = int(request.form["Number_vid"])
31+
duration = int(request.form["duration"])
32+
Email = request.form["email"]
33+
with concurrent.futures.ThreadPoolExecutor() as executor:
34+
executor.submit(process_audio, singer, Number_vid, duration, Email)
35+
# process_audio(singer,Number_vid,duration)
36+
# email=request.form['email']
37+
return redirect("/success")
38+
return render_template("index.html")
39+
40+
41+
def process_audio(singer, Number_vid, duration, Email):
42+
singer1 = singer + "songs"
43+
results1 = YoutubeSearch(singer1, max_results=Number_vid).to_dict()
44+
data = pd.DataFrame(results1)
45+
for i in range(1, (data["url_suffix"].count())):
46+
data["url_suffix"][i] = "https://www.youtube.com" + data["url_suffix"][i]
47+
links = data["url_suffix"]
48+
for i in links:
49+
# yt = YouTube(str(i))
50+
yt = YouTube(i, use_oauth=True, allow_oauth_cache=True)
51+
# print(yt.title)
52+
# if(yt.length<100):
53+
# extract only audio
54+
video = yt.streams.filter(file_extension="mp4", only_audio=True).first()
55+
# download the file
56+
out_file = video.download()
57+
# save the file
58+
base, ext = os.path.splitext(out_file)
59+
new_file = base + ".mp4"
60+
os.rename(out_file, new_file)
61+
audio_files = []
62+
for file in os.listdir():
63+
if file.endswith(".mp4"):
64+
audio = AudioSegment.from_file(file, "mp4")
65+
audio_file = file.replace(".mp4", ".wav")
66+
audio.export(audio_file, format="wav")
67+
audio_files.append(audio_file)
68+
chunks = []
69+
# print(audio_files)
70+
for audio_file in audio_files:
71+
chunk = make_chunks(
72+
AudioSegment.from_file(audio_file, format="wav"),
73+
chunk_length=duration * 1000,
74+
)
75+
id = np.random.randint(0, len(chunk))
76+
chunk = chunk[id]
77+
# print(chunk)
78+
chunks.append(chunk)
79+
merged = AudioSegment.empty()
80+
for chunk in chunks:
81+
merged += chunk
82+
merged.export("output.mp3", format="mp3")
83+
dir = os.getcwd()
84+
test = os.listdir(dir)
85+
for item in test:
86+
if item.endswith(".mp4"):
87+
os.remove(os.path.join(dir, item))
88+
if item.endswith(".wav"):
89+
os.remove(os.path.join(dir, item))
90+
with zipfile.ZipFile("output.zip", "w") as zipf:
91+
zipf.write("output.mp3")
92+
msg = MIMEMultipart()
93+
msg["From"] = "noobbobby241@gmail.com"
94+
msg["To"] = COMMASPACE.join([Email])
95+
msg["Date"] = formatdate(localtime=True)
96+
msg["Subject"] = "Downloaded and Converted Audio"
97+
98+
with open("output.zip", "rb") as f:
99+
part = MIMEBase("application", "octet-stream")
100+
part.set_payload(f.read())
101+
102+
encoders.encode_base64(part)
103+
part.add_header("Content-Disposition", "attachment", filename="output.zip")
104+
msg.attach(part)
105+
smtp = smtplib.SMTP("smtp.gmail.com", 587)
106+
smtp.ehlo()
107+
smtp.starttls()
108+
smtp.ehlo()
109+
smtp.login("noobbobby241@gmail.com", "cliwqftyqujpisht")
110+
smtp.sendmail("noobbobby241@gmail.com", [Email], msg.as_string())
111+
print("Email Sent")
112+
113+
114+
@app.route("/success")
115+
def success():
116+
return render_template("success.html")
117+
118+
119+
# @app.route('/download')
120+
# def download():
121+
# #@after_this_request
122+
# #def cleanup(response):
123+
# #cleanup_directory()
124+
# #return response
125+
# return send_file('output.zip', as_attachment=True)
126+
# def cleanup_directory():
127+
# test = os.listdir()
128+
# for item in test:
129+
# if item.endswith(".mp3"):
130+
# os.remove(os.path.join(os.getcwd(), item))
131+
# if item.endswith(".zip"):
132+
# os.remove(os.path.join(os.getcwd(), item))
133+
if __name__ == "__main__":
134+
app.debug = True
135+
app.run(host="0.0.0.0", port=5000)

0 commit comments

Comments
 (0)