diff --git a/PROJECT_1_FIBONACCI_GENERATOR.PY b/PROJECT_1_FIBONACCI_GENERATOR.PY new file mode 100644 index 0000000..36b26de --- /dev/null +++ b/PROJECT_1_FIBONACCI_GENERATOR.PY @@ -0,0 +1,9 @@ +def fibonacci(n): + if n <= 1: + return n + return fibonacci(n-1) + fibonacci(n-2) + +n = int(input("Enter number of terms :")) + +for i in range (n): + print(fibonacci(i), end=" ") \ No newline at end of file diff --git a/PROJECT_2_VOICE_ASSISTANT.PY b/PROJECT_2_VOICE_ASSISTANT.PY new file mode 100644 index 0000000..1a5fe3b --- /dev/null +++ b/PROJECT_2_VOICE_ASSISTANT.PY @@ -0,0 +1,67 @@ +import speech_recognition as sr +import pyttsx3 +import webbrowser +import datetime +import wikipedia + +# initialize +engine = pyttsx3.init() +recognizer = sr.Recognizer() + +def speak(text): + engine.say(text) + engine.runAndWait() + +def listen(): + with sr.Microphone() as source: + print("Listening...") + audio = recognizer.listen(source) + try: + command = recognizer.recognize_google(audio) + print("You said:", command) + return command.lower() + except: + speak("Sorry, I didn't catch that") + return "" + +def process_command(command): + if "hello" in command: + speak("Hello Ronit! How can I help you?") + + elif "time" in command: + time = datetime.datetime.now().strftime("%H:%M") + speak(f"The time is {time}") + + elif "open youtube" in command: + webbrowser.open("https://www.youtube.com") + speak("Opening YouTube") + + elif "open my github profile" in command: + webbrowser.open("https://www.github.com/Ronit049") + speak("Opening Your github profile Ronit") + + elif "open my Twitter profile" in command: + webbrowser.open("https://x.com/its_rsr04") + speak("Opening your twitter profile") + + elif "search" in command: + speak("What should I search?") + query = listen() + webbrowser.open(f"https://www.google.com/search?q={query}") + + elif "wikipedia" in command: + speak("Searching Wikipedia...") + query = command.replace("wikipedia", "") + result = wikipedia.summary(query, sentences=2) + speak(result) + + elif "exit" in command: + speak("Goodbye!") + exit() + +# main loop +speak("Voice assistant started") + +while True: + command = listen() + process_command(command) \ No newline at end of file diff --git a/PROJECT_3_Game_of_Tic-Tac-Toe.PY b/PROJECT_3_Game_of_Tic-Tac-Toe.PY new file mode 100644 index 0000000..b91f014 --- /dev/null +++ b/PROJECT_3_Game_of_Tic-Tac-Toe.PY @@ -0,0 +1,56 @@ +import tkinter as tk +from tkinter import messagebox + +def check_winner(): + global winner + for combo in [[0,1,2],[3,4,5],[6,7,8], + [0,3,6],[1,4,7],[2,5,8], + [0,4,8],[2,4,6]]: + + if buttons[combo[0]]["text"] == buttons[combo[1]]["text"] == buttons[combo[2]]["text"] != "": + + # highlight winner + for i in combo: + buttons[i].config(bg="green") + + messagebox.showinfo("Tic-Tac-Toe", f"Player {buttons[combo[0]]['text']} wins!") + winner = True + + # disable all buttons + for b in buttons: + b.config(state="disabled") + +def button_click(index): + if buttons[index]["text"] == "" and not winner: + buttons[index]["text"] = current_player + check_winner() + if not winner: + toggle_player() + +def toggle_player(): + global current_player + current_player = "X" if current_player == "O" else "O" + label.config(text=f"Player {current_player}'s turn") + +# main window +root = tk.Tk() +root.title("Tic-Tac-Toe") + +buttons = [ + tk.Button(root, text="", font=("normal",25), + width=6, height=2, + command=lambda i=i: button_click(i)) + for i in range(9) +] + +# grid layout +for i, button in enumerate(buttons): + button.grid(row=i // 3, column=i % 3) + +current_player = "X" +winner = False + +label = tk.Label(root, text=f"Player {current_player}'s turn", font=("normal",16)) +label.grid(row=3, column=0, columnspan=3) + +root.mainloop() \ No newline at end of file