Skip to content

Commit f49ce6b

Browse files
authored
Add files via upload
1 parent c498739 commit f49ce6b

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

PROJECT_1_FIBONACCI_GENERATOR.PY

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def fibonacci(n):
2+
if n <= 1:
3+
return n
4+
return fibonacci(n-1) + fibonacci(n-2)
5+
6+
n = int(input("Enter number of terms :"))
7+
8+
for i in range (n):
9+
print(fibonacci(i), end=" ")

PROJECT_2_VOICE_ASSISTANT.PY

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import speech_recognition as sr
2+
import pyttsx3
3+
import webbrowser
4+
import datetime
5+
import wikipedia
6+
7+
# initialize
8+
engine = pyttsx3.init()
9+
recognizer = sr.Recognizer()
10+
11+
def speak(text):
12+
engine.say(text)
13+
engine.runAndWait()
14+
15+
def listen():
16+
with sr.Microphone() as source:
17+
print("Listening...")
18+
audio = recognizer.listen(source)
19+
try:
20+
command = recognizer.recognize_google(audio)
21+
print("You said:", command)
22+
return command.lower()
23+
except:
24+
speak("Sorry, I didn't catch that")
25+
return ""
26+
27+
def process_command(command):
28+
if "hello" in command:
29+
speak("Hello Ronit! How can I help you?")
30+
31+
elif "time" in command:
32+
time = datetime.datetime.now().strftime("%H:%M")
33+
speak(f"The time is {time}")
34+
35+
elif "open youtube" in command:
36+
webbrowser.open("https://www.youtube.com")
37+
speak("Opening YouTube")
38+
39+
elif "open my github profile" in command:
40+
webbrowser.open("https://www.github.com/Ronit049")
41+
speak("Opening Your github profile Ronit")
42+
43+
elif "open my Twitter profile" in command:
44+
webbrowser.open("https://x.com/its_rsr04")
45+
speak("Opening your twitter profile")
46+
47+
elif "search" in command:
48+
speak("What should I search?")
49+
query = listen()
50+
webbrowser.open(f"https://www.google.com/search?q={query}")
51+
52+
elif "wikipedia" in command:
53+
speak("Searching Wikipedia...")
54+
query = command.replace("wikipedia", "")
55+
result = wikipedia.summary(query, sentences=2)
56+
speak(result)
57+
58+
elif "exit" in command:
59+
speak("Goodbye!")
60+
exit()
61+
62+
# main loop
63+
speak("Voice assistant started")
64+
65+
while True:
66+
command = listen()
67+
process_command(command)

PROJECT_3_Game_of_Tic-Tac-Toe.PY

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import tkinter as tk
2+
from tkinter import messagebox
3+
4+
def check_winner():
5+
global winner
6+
for combo in [[0,1,2],[3,4,5],[6,7,8],
7+
[0,3,6],[1,4,7],[2,5,8],
8+
[0,4,8],[2,4,6]]:
9+
10+
if buttons[combo[0]]["text"] == buttons[combo[1]]["text"] == buttons[combo[2]]["text"] != "":
11+
12+
# highlight winner
13+
for i in combo:
14+
buttons[i].config(bg="green")
15+
16+
messagebox.showinfo("Tic-Tac-Toe", f"Player {buttons[combo[0]]['text']} wins!")
17+
winner = True
18+
19+
# disable all buttons
20+
for b in buttons:
21+
b.config(state="disabled")
22+
23+
def button_click(index):
24+
if buttons[index]["text"] == "" and not winner:
25+
buttons[index]["text"] = current_player
26+
check_winner()
27+
if not winner:
28+
toggle_player()
29+
30+
def toggle_player():
31+
global current_player
32+
current_player = "X" if current_player == "O" else "O"
33+
label.config(text=f"Player {current_player}'s turn")
34+
35+
# main window
36+
root = tk.Tk()
37+
root.title("Tic-Tac-Toe")
38+
39+
buttons = [
40+
tk.Button(root, text="", font=("normal",25),
41+
width=6, height=2,
42+
command=lambda i=i: button_click(i))
43+
for i in range(9)
44+
]
45+
46+
# grid layout
47+
for i, button in enumerate(buttons):
48+
button.grid(row=i // 3, column=i % 3)
49+
50+
current_player = "X"
51+
winner = False
52+
53+
label = tk.Label(root, text=f"Player {current_player}'s turn", font=("normal",16))
54+
label.grid(row=3, column=0, columnspan=3)
55+
56+
root.mainloop()

0 commit comments

Comments
 (0)