diff --git a/0x09-Shutdown/main.py b/0x09-Shutdown/main.py index ef08bc5..148c2dc 100644 --- a/0x09-Shutdown/main.py +++ b/0x09-Shutdown/main.py @@ -8,7 +8,7 @@ def systemOffRestart(): import os print("enter r for restart") print("enter s for shutdown") - print("enter any key for exot") + print("enter any key for exit") option = input("enter your option") if option == "r": diff --git a/Dice-Simulator/README.md b/Dice-Simulator/README.md new file mode 100644 index 0000000..ddb2baa --- /dev/null +++ b/Dice-Simulator/README.md @@ -0,0 +1,2 @@ +# Dice-Simulator + diff --git a/Dice-Simulator/img/five.png b/Dice-Simulator/img/five.png new file mode 100644 index 0000000..620c791 Binary files /dev/null and b/Dice-Simulator/img/five.png differ diff --git a/Dice-Simulator/img/four.png b/Dice-Simulator/img/four.png new file mode 100644 index 0000000..ee6cdee Binary files /dev/null and b/Dice-Simulator/img/four.png differ diff --git a/Dice-Simulator/img/one.png b/Dice-Simulator/img/one.png new file mode 100644 index 0000000..ab4d240 Binary files /dev/null and b/Dice-Simulator/img/one.png differ diff --git a/Dice-Simulator/img/six.png b/Dice-Simulator/img/six.png new file mode 100644 index 0000000..7951926 Binary files /dev/null and b/Dice-Simulator/img/six.png differ diff --git a/Dice-Simulator/img/three.png b/Dice-Simulator/img/three.png new file mode 100644 index 0000000..c174095 Binary files /dev/null and b/Dice-Simulator/img/three.png differ diff --git a/Dice-Simulator/img/two.png b/Dice-Simulator/img/two.png new file mode 100644 index 0000000..2e8fc64 Binary files /dev/null and b/Dice-Simulator/img/two.png differ diff --git a/Dice-Simulator/main.py b/Dice-Simulator/main.py new file mode 100644 index 0000000..d1ee205 --- /dev/null +++ b/Dice-Simulator/main.py @@ -0,0 +1,20 @@ +import customtkinter +from PIL import Image +import random + +img = ["one", "two", "three", "four", "five", "six"] +def button_callback(): + choice = random.choice(img) + my_image = customtkinter.CTkImage(light_image=Image.open("img\\"+choice+".png"),size=(100, 100)) + image_label = customtkinter.CTkLabel(app, image=my_image, text="") + image_label.grid(row=1, column=0, padx=20, pady=20) + +app = customtkinter.CTk() +app.title("Dice Roll") +app.geometry("350x200") +app.grid_columnconfigure(0, weight=1) + +button = customtkinter.CTkButton(app, text="Roll", command=button_callback) +button.grid(row=0, column=0, padx=20, pady=20) + +app.mainloop() \ No newline at end of file diff --git a/JSON-to-CSV/README.md b/JSON-to-CSV/README.md new file mode 100644 index 0000000..2cbab3f --- /dev/null +++ b/JSON-to-CSV/README.md @@ -0,0 +1,2 @@ +# JSON to CSV + JSON to CSV Converter diff --git a/JSON-to-CSV/json2csv.py b/JSON-to-CSV/json2csv.py new file mode 100644 index 0000000..92b2538 --- /dev/null +++ b/JSON-to-CSV/json2csv.py @@ -0,0 +1,52 @@ +import json +import csv +import os + +print("\nWelcome to the JSON to CSV converter") + +class Converter: + + def converter(self, json_file_path, csv_file_name): + global data + if json_file_path == 1: + try: + with open(json_file_path, 'r') as f1: + data = json.load(f1) + except: + print("File not found") + print("Try creating a new json file") + return + + if json_file_path == 2: + f = open("input.json",'x') + f.close() + file = "notepad input.json" + os.system(file) + f1 = open("input.json",'r') + data = json.load(f1) + + f2 = open(csv_file_name, 'w', newline="") + writer_object = csv.writer(f2) + writer_object.writerow(data[0].keys()) + + for row in data: + writer_object.writerow(row.values()) + f2.close() + + choice = input("Do you want open the converted file? (y/n): ") + while choice not in ['y','n']: + print("Invalid choice") + choice = input("Do you want open the converted file? (y/n): ") + if choice == 'y': + os.system(f'start "excel" {csv_file_name}') + +json2csv = Converter() + +json_file_path = int(input(""" +Press (1) to Open an existing json file +Press (2) to Create a new json file and Enter your data +Choose any one: """)) + +csv_file_name = input("Name your CSV file: ")+".csv" + +json2csv.converter(json_file_path, csv_file_name) \ No newline at end of file diff --git a/Memory Game Python/README.md b/Memory Game Python/README.md new file mode 100644 index 0000000..26dbf4a --- /dev/null +++ b/Memory Game Python/README.md @@ -0,0 +1,34 @@ +### + +# Memory Game Python Script Breakdown + +## 1. Importing Necessary Modules +- **random**: for generating random numbers. +- **tabulate**: for formatting the grid display. +- **os**: for clearing the console. + +## 2. Defining Global Variables +- **values**: a dictionary mapping letters to their corresponding indices in the grid. +- **temp_found**: a list to store the numbers temporarily found during each turn. +- **user_values**: a list to store the user's input for each turn. +- **user_choices**: a list to keep track of the tiles already uncovered by the user. +- **progress**: a boolean flag to indicate whether the game is still in progress. +- **competed**: a boolean flag to indicate whether the game has been completed. + +## 3. Taking User Input for the Grid Size +- The user is prompted to enter a choice for the grid size (e.g., 2 for a 2x2 grid, 4 for a 4x4 grid). +- The input is validated to ensure it is an even number. + +## 4. Defining Functions +- **game_elements(num)**: a function that generates the grid elements. It creates a list of random numbers and shuffles them to create pairs. +- **game_process(num)**: a function that handles the game logic. It displays the grid, prompts the user for input, and updates the grid based on the user's choices. It also checks for matches and updates the game status accordingly. + +## 5. The Main Game Loop +- The main list is populated with the grid elements using the `game_elements` function. +- The `game_process` function is called to start the game. +- After each game, the user is prompted to choose whether to play again. +- If the user chooses to quit, the loop breaks. + +**Overall, the selected code provides a complete implementation of the memory game with user interaction and grid display.** + +### diff --git a/Memory Game Python/main.py b/Memory Game Python/main.py new file mode 100644 index 0000000..2939a70 --- /dev/null +++ b/Memory Game Python/main.py @@ -0,0 +1,151 @@ +import random +import os + +values = {'a' : 0, 'b' : 1, 'c' : 2, 'd' : 3, 'e' : 4, 'f' : 5, 'g' : 6, 'h' : 7} +table_heading = {65:"A", 66:"B", 67:"C", 68:"D", 69:"E", 70:"F", 71:"G", 72:"H"} +temp_found = [] +user_values = [] +user_choices = [] +progress = True +competed = False + +def game_elements(num): + + lst = [] + while len(lst) < num: + row = [] + while len(row) < num: + random_number = random.randint(65,73) + if random_number not in row: + row.append(chr(random_number)) + lst.append(row) + element = row.copy() + random.shuffle(element) + lst.append(element) + return lst + +def game_process(num): + global user_values + global temp_found + global competed + + def game_table(list_with_spaces): + char_count = 65 + if user_choice_data == 2: + print(" 0 1 ") + print(" |---------|---------|") + for i in range(2): + print(f"{table_heading[char_count]} | {list_with_spaces[i][0]} | {list_with_spaces[i][1]} |") + print(" |---------|---------|") + char_count += 1 + + if user_choice_data == 4: + print(" 0 1 2 3 ") + print(" |---------|---------|---------|---------|") + for i in range(4): + print(f"{table_heading[char_count]} | {list_with_spaces[i][0]} | {list_with_spaces[i][1]} | {list_with_spaces[i][2]} | {list_with_spaces[i][3]} |") + print(" |---------|---------|---------|---------|") + char_count += 1 + + if user_choice_data == 6: + print(" 0 1 2 3 4 5 ") + print(" |-------|-------|-------|-------|-------|-------|") + for i in range(6): + print(f"{table_heading[char_count]} | {list_with_spaces[i][0]} | {list_with_spaces[i][1]} | {list_with_spaces[i][2]} | {list_with_spaces[i][3]} | {list_with_spaces[i][4]} | {list_with_spaces[i][5]} |") + print(" |-------|-------|-------|-------|-------|-------|") + char_count += 1 + + if user_choice_data == 8: + print(" 0 1 2 3 4 5 6 7 ") + print(" |-------|-------|-------|-------|-------|-------|-------|-------|") + for i in range(8): + print(f"{table_heading[char_count]} | {list_with_spaces[i][0]} | {list_with_spaces[i][1]} | {list_with_spaces[i][2]} | {list_with_spaces[i][3]} | {list_with_spaces[i][4]} | {list_with_spaces[i][5]} | {list_with_spaces[i][6]} | {list_with_spaces[i][7]} |") + print(" |-------|-------|-------|-------|-------|-------|-------|-------|") + char_count += 1 + + list_with_spaces = [[' ' for _ in sublist] for sublist in main] + while progress: + os.system('cls') + game_table(list_with_spaces) + + trial = 0 + for i in range(2): + if len(user_choices) == (num**2): + competed = True + break + + opn = input("\nEnter the tile to uncover: ") + while opn in user_choices: + print("\n===========>>>You have already completed this tile!") + opn = input("\nEnter the new tile to uncover: ") + user_values.append(opn) + + index_1 = values[opn[0]] + index_2 = int(opn[1]) + + temp_found.append(main[index_1][index_2]) + + list_with_spaces[index_1][index_2] = main[index_1][index_2] + game_table(list_with_spaces) + + trial += 1 + if trial == 2: + user_input = input("\n===========>>> Press (Enter) to Continue: ") + trial = 0 + + if competed: + print("\n===========>>> You Won! <<<===========") + break + elif temp_found[0] == temp_found[1]: + for i in range(2): + user_choices.append(user_values[i]) + index_1 = values[user_values[i][0]] + index_2 = int(user_values[i][1]) + list_with_spaces[index_1][index_2] = "✔️" + user_values = [] + temp_found = [] + else: + for i in range(2): + index_1 = values[user_values[i][0]] + index_2 = int(user_values[i][1]) + list_with_spaces[index_1][index_2] = " " + user_values = [] + temp_found = [] +while True: + user_choice_data = input(""" +For '2x2' enter "EASY" +For '4x4' enter "MEDIUM" +For '6x6' enter "HARD" +For '8x8' enter "EXTREME" + +Enter your choice: """).lower() + + while user_choice_data not in ["easy", "medium", "hard", "extreme"]: + os.system("cls") + user_choice_data = input(""" +For '2x2' enter "EASY" +For '4x4' enter "MEDIUM" +For '6x6' enter "HARD" +For '8x8' enter "EXTREME" + +Enter your choice: """).lower() + + if user_choice_data == "easy": + user_choice_data = 2 + if user_choice_data == "medium": + user_choice_data = 4 + if user_choice_data == "hard": + user_choice_data = 6 + if user_choice_data == "extreme": + user_choice_data = 8 + main = game_elements(user_choice_data) + process = game_process(user_choice_data) + + choice = input("Do you want to play the game again? (y/n): ").lower() + + while choice not in ["y", "n"]: + print("\n Invalid choice") + choice = input("Do you want to play the game again? (y/n): ") + + if choice == "n": + break \ No newline at end of file diff --git a/OOP Example/main.py b/OOP Example/main.py new file mode 100644 index 0000000..ad30b5b --- /dev/null +++ b/OOP Example/main.py @@ -0,0 +1,20 @@ +# Class Creation +class Person: + # Initialization function (when you create an object this named initialization) + def __init__(self,name,age): + # changing objects attributes to arguments that we enter when calling an class to create an object + self.name = name + self.age = age + + # String function that returns a string that will be returned if you will print class + # Without __str__(): <__main__.Person object at 0x000001AC025E7230> + # With __str__(): + def __str__(self): + return f'Name: {self.name}. Age: {self.age}' + +# Creating an object using class +p = Person("John",21) # you can change the values and create some other methods in class +print(p) + +# Output: +# Name: John. Age: 21 diff --git a/PDF summrazation/main.py b/PDF summrazation/main.py new file mode 100644 index 0000000..5f7d744 --- /dev/null +++ b/PDF summrazation/main.py @@ -0,0 +1,118 @@ +import tkinter as tk +from tkinter import filedialog, scrolledtext, messagebox, simpledialog, font +from tkinter import PhotoImage # Import PhotoImage for handling images +import torch +from transformers import T5Tokenizer, T5ForConditionalGeneration +from pdfminer.high_level import extract_text +import requests +from io import BytesIO +from fpdf import FPDF # Import FPDF for PDF generation + +model = T5ForConditionalGeneration.from_pretrained('t5-small') +tokenizer = T5Tokenizer.from_pretrained('t5-small') +device = torch.device('cpu') + +def pdf_to_text(pdf_path): + try: + text = extract_text(pdf_path) + return text + except Exception as e: + print(f"Error extracting text from PDF: {e}") + return None + +def summarize_text(text): + preprocess_text = text.strip().replace("\n", " ") + t5_prepared_text = "summarize: " + preprocess_text + tokenized_text = tokenizer.encode(t5_prepared_text, return_tensors="pt").to(device) + summary_ids = model.generate(tokenized_text, + num_beams=4, + no_repeat_ngram_size=2, + min_length=30, + max_length=100, + early_stopping=True) + output = tokenizer.decode(summary_ids[0], skip_special_tokens=True) + return output + +def download_pdf(url): + try: + response = requests.get(url) + response.raise_for_status() + return BytesIO(response.content) + except requests.RequestException as e: + messagebox.showerror("Download Error", f"Failed to download PDF: {e}") + return None + +def select_files(): + file_paths = filedialog.askopenfilenames(filetypes=[("PDF files", "*.pdf")]) + if file_paths: + summaries = [summarize_text(pdf_to_text(pdf_file)) for pdf_file in file_paths if + pdf_to_text(pdf_file) is not None] + output_text.delete('1.0', tk.END) + output_text.insert(tk.END, "\n\n".join(summaries)) + messagebox.showinfo("Completion", "Summarization completed!") + else: + messagebox.showinfo("No Files", "No PDF files were selected.") + +def fetch_from_url(): + url = simpledialog.askstring("Enter URL", "Please enter the PDF URL:") + if url: + pdf_file = download_pdf(url) + if pdf_file: + summary = summarize_text(pdf_to_text(pdf_file)) + output_text.delete('1.0', tk.END) + output_text.insert(tk.END, summary) + messagebox.showinfo("Completion", "Summarization completed!") + +def save_summary_as_pdf(): + text_to_save = output_text.get('1.0', tk.END) + if not text_to_save.strip(): + messagebox.showerror("No Data", "There is no summary to save.") + return + + file_path = filedialog.asksaveasfilename(defaultextension=".pdf", filetypes=[("PDF files", "*.pdf")]) + if file_path: + pdf = FPDF() + pdf.add_page() + + # Calculate center position for logo and title + logo_x = (pdf.w - 30) / 2 # Centering logo horizontally + pdf.image("p.png", x=logo_x, y=10, w=30) + pdf.ln(28) + # Add header title centered + pdf.set_font("Arial", size=12) + pdf.cell(0, 10, "MGM's College Of Engineering", ln=True, align='C') + + # Add line separator + pdf.set_line_width(0.5) + pdf.line(10, 50, pdf.w - 10, 50) + + # Add summary text + pdf.set_font("Arial", size=10) + pdf.multi_cell(0, 10, text_to_save) + + pdf.output(file_path) + + messagebox.showinfo("Saved as PDF", "The summary has been saved as PDF!") + +app = tk.Tk() +app.title("PDF Summarizer") +app.geometry("800x600") +app.config(bg="light blue") +customFont = font.Font(family="Helvetica", size=12) + +btn_load = tk.Button(app, text="Load PDFs", command=select_files, font=customFont, bg="navy", fg="white", padx=10, + pady=5) +btn_load.pack(pady=10) + +btn_fetch = tk.Button(app, text="Fetch PDF from URL", command=fetch_from_url, font=customFont, bg="navy", fg="white", + padx=10, pady=5) +btn_fetch.pack(pady=10) + +btn_save_pdf = tk.Button(app, text="Save Summary as PDF", command=save_summary_as_pdf, font=customFont, bg="navy", + fg="white", padx=10, pady=5) +btn_save_pdf.pack(pady=10) + +output_text = scrolledtext.ScrolledText(app, width=70, height=20, font=customFont, padx=10, pady=10, wrap=tk.WORD) +output_text.pack(pady=20) + +app.mainloop() diff --git a/PDF summrazation/p.png b/PDF summrazation/p.png new file mode 100644 index 0000000..6c493e0 Binary files /dev/null and b/PDF summrazation/p.png differ diff --git a/Quiz-Creator/quiz.py b/Quiz-Creator/quiz.py new file mode 100644 index 0000000..2a4f770 --- /dev/null +++ b/Quiz-Creator/quiz.py @@ -0,0 +1,19 @@ +import os +class QuizCreation: + def process(self, question, choices, answer, question_number=""): + choices_dict = {'a':1, 'b':2, 'c':3, 'd':4} + with open("sample.txt", "a") as f: + f.write(f"\nQUESTION {question_number}:- "+question) + f.write("\n") + count = 65 + for i in range(len(choices)): + f.write(f"({chr(count)}) "+choices[i]) + f.write("\n") + count += 1 + f.write(f"Answer :- ({answer.upper()}) "+choices[choices_dict[answer]-1]) + f.write("\n") + + def open_file(self): + os.startfile("sample.txt") + +Quiz = QuizCreation() \ No newline at end of file diff --git a/Quiz-Creator/sample.py b/Quiz-Creator/sample.py new file mode 100644 index 0000000..19a8a3b --- /dev/null +++ b/Quiz-Creator/sample.py @@ -0,0 +1,7 @@ +from quiz import Quiz + +Quiz.process(question="Entomology is the science that studies", + choices=["Behavior of human beings", "Insects", "The origin and history of technical and scientific terms", "The formation of rocks"], + answer="b") + +Quiz.open_file() \ No newline at end of file diff --git a/Quiz-Creator/sample.txt b/Quiz-Creator/sample.txt new file mode 100644 index 0000000..d57ef88 --- /dev/null +++ b/Quiz-Creator/sample.txt @@ -0,0 +1,7 @@ + +QUESTION :- Entomology is the science that studies +(A) Behavior of human beings +(B) Insects +(C) The origin and history of technical and scientific terms +(D) The formation of rocks +Answer :- (B) Insects diff --git a/README.md b/README.md index e1c9baf..0d7712d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,12 @@ | 21 | [Web Cloner](./0x23-WebCloner) | | 24 | [Chess Game](./0x24-Chess_Game) | | 25 | [Quiz Master](./0x25-QuizMaster) | +| 26 | [Dice-Simulator](./Dice-Simulator) | +| 27 | [JSON-to-CSV](./JSON-to-CSV) | +| 28 | [Memory Game Python](./Memory-Game-Python) | +| 29 | [Quiz-Creator](./Quiz-Creator) | +| 28 | [Memory-Game-Python](./Memory%20Game%20Python) | + @@ -73,6 +79,9 @@ flowchart LR dayoonasanya
Adedayo Onasanya

💻 Atughara John
Atughara John

💻 levoski1
Ugwoke Levi

💻 + Manavalan
Manavalan

💻 + P0Saurabh
P0Saurabh

💻 + wCupped
wCupped
💻