diff --git a/SamridhiGupta/Calculator/Calculator.py b/SamridhiGupta/Calculator/Calculator.py new file mode 100644 index 0000000..b25bc5c --- /dev/null +++ b/SamridhiGupta/Calculator/Calculator.py @@ -0,0 +1,46 @@ +def perform_operation(operator, num1, num2): + if operator == "+": + return num1 + num2 + elif operator == "-": + return num1 - num2 + elif operator == "*": + return num1 * num2 + elif operator == "/": + if num2 != 0: + return num1 / num2 + else: + return "Error: Division by zero is not allowed" + +def calculator(): + operations = { + "+": "add", + "-": "subtract", + "*": "multiply", + "/": "divide", + "quit": "end the program" + } + + while True: + print("Options:") + for op, desc in operations.items(): + print(f"Enter '{op}' to {desc}") + + user_input = input("Enter your operator: ") + + if user_input == "quit": + break + elif user_input in operations: + try: + num1, num2 = map(float, input("Enter two numbers separated by space: ").split()) + + result = perform_operation(user_input, num1, num2) + + print(f"Result: {num1} {user_input} {num2} = {result}") + + except ValueError: + print("Invalid Input: Please enter two numerical values separated by space.") + else: + print("Invalid Input: Please enter a valid operator") + +# Call the calculator function to start the program +calculator() diff --git a/SamridhiGupta/Calculator/Readme.md b/SamridhiGupta/Calculator/Readme.md new file mode 100644 index 0000000..cb93ea9 --- /dev/null +++ b/SamridhiGupta/Calculator/Readme.md @@ -0,0 +1,63 @@ +# Calculator Program + +## Overview + +This is a simple calculator program written in Python. It supports basic arithmetic operations including Addition, Subtraction, Multiplication, and Division. The user can interact with the program through a command-line interface to perform calculations. + +## Features + +- **Addition (`+`)**: Adds two numbers. +- **Subtraction (`-`)**: Subtracts the second number from the first number. +- **Multiplication (`*`)**: Multiplies two numbers. +- **Division (`/`)**: Divides the first number by the second number. If the second number is zero, it returns an error message. +- **Quit (`quit`)**: Ends the program. + +## How to Use + +1. Run the script to start the calculator. +2. The program will display a list of options for the available operations. +3. Enter the operator for the desired operation. +4. Enter two numbers separated by a space when prompted. +5. The result of the operation will be displayed. +6. To exit the program, enter `quit` when asked for the operator. + +## Example +``` +Options: +Enter '+' to add +Enter '-' to subtract +Enter '*' to multiply +Enter '/' to divide +Enter 'quit' to end the program +Enter your operator: + +Enter two numbers separated by space: 5 3 +Result: 5.0 + 3.0 = 8.0 +``` + +## Error Handling +The calculator program includes basic error handling to manage common errors: + +1. **Division by Zero:** + +- If the user attempts to divide by zero, the program will return the following error message: +``` +Enter your operator: / +Enter two numbers separated by space: 10 0 +Result: 10.0 / 0.0 = Error: Division by zero is not allowed +``` +2. **Invalid Numerical Input** + +- If the user enters non-numerical values or an incorrect format for the numbers, the program will catch a ValueError and display the following message: +``` +Enter your operator: + +Enter two numbers separated by space: 10 a +Invalid Input: Please enter two numerical values separated by space. +``` +3. **Invalid Operator:** + +- If the user enters an operator that is not supported, the program will display the following message: +``` +Enter your operator: % +Invalid Input: Please enter a valid operator +``` + diff --git a/SamridhiGupta/Number_Game/Number_Game.py b/SamridhiGupta/Number_Game/Number_Game.py new file mode 100644 index 0000000..57167d7 --- /dev/null +++ b/SamridhiGupta/Number_Game/Number_Game.py @@ -0,0 +1,34 @@ +import random + +def random_number_game(): + # Generate a random number between 1 and 100 + target_number = random.randint(1, 100) + print("The computer has chosen a number!") + print("ARE YOU READY TO GUESS THE NUMBER!!") + + max_attempts = 4 + attempts = 0 + + print("Let's start the game") + print(f"Choose a number between 1 and 100\nNOTE: You will have {max_attempts} attempts to guess the number") + + while attempts < max_attempts: + try: + guess = int(input("Enter your guess: ")) + attempts += 1 + + if guess < target_number: + print(f"The value you guessed is less than the computer generated number. You have used {attempts} out of {max_attempts} attempts. Try again!") + elif guess > target_number: + print(f"The value you guessed is greater than the computer generated number. You have used {attempts} out of {max_attempts} attempts. Try again!") + else: + print("Congratulations! You guessed the number correctly!") + print(f"You took {attempts} attempts") + return + except ValueError: + print("Invalid Input: Please enter a valid number.") + + print("You've run out of attempts! The correct number was", target_number) + +# Call the function to start the game +random_number_game() diff --git a/SamridhiGupta/Number_Game/Readme.md b/SamridhiGupta/Number_Game/Readme.md new file mode 100644 index 0000000..6b70f93 --- /dev/null +++ b/SamridhiGupta/Number_Game/Readme.md @@ -0,0 +1,49 @@ +# Random Number Guessing Game + +## Overview + +This is a simple Python program where the user tries to guess a random number chosen by the computer. The number is between 1 and 100, and the user has a limited number of attempts to guess it correctly. + +## Features + +- **Random Number Generation**: The program generates a random number between 1 and 100 at the start of each game. +- **User Input**: The user is prompted to enter their guess. +- **Feedback**: The program provides feedback if the guess is too high or too low. +- **Limited Attempts**: The user has up to 4 attempts to guess the number correctly. +- **Victory and Loss Messages**: The program displays a congratulatory message if the user guesses correctly, and a message with the correct number if the user runs out of attempts. + +## How to Use + +1. **Run the Program**: Execute the script to start the game. +2. **Start Guessing**: Follow the on-screen instructions to enter your guesses. +3. **Receive Feedback**: After each guess, the program will tell you if your guess is too high, too low, or correct. +4. **Win or Lose**: The game ends either when you guess the number correctly or when you run out of attempts. + +## Example Usage + +``` +The computer has chosen a number! +ARE YOU READY TO GUESS THE NUMBER!! +Let's start the game +Choose a number between 1 and 100 +NOTE: You will have 4 attempts to guess the number +Enter your guess: 50 +The value you guessed is less than the computer generated number. You have used 1 out of 4 attempts. Try again! +Enter your guess: 75 +The value you guessed is greater than the computer generated number. You have used 2 out of 4 attempts. Try again! +Enter your guess: 60 +The value you guessed is less than the computer generated number. You have used 3 out of 4 attempts. Try again! +Enter your guess: 70 +Congratulations! You guessed the number correctly! +You took 4 attempts +``` +## Error Handling + +The program includes basic error handling to manage common input errors: + +1. **Invalid Input**: + - If the user enters a non-numeric value, the program will display the message: `Invalid Input: Please enter a valid number.` + - The attempt will not be counted in case of an invalid input. + +2. **Out of Attempts**: + - If the user does not guess the number correctly within the allowed attempts, the program will display the correct number and end the game. diff --git a/SamridhiGupta/PDF_Converter/PDF_Converter.py b/SamridhiGupta/PDF_Converter/PDF_Converter.py new file mode 100644 index 0000000..6d5913b --- /dev/null +++ b/SamridhiGupta/PDF_Converter/PDF_Converter.py @@ -0,0 +1,53 @@ +import fitz +import os + +def convert_pdf_to_text(pdf_path, output_path): + """ + Convert a PDF file to a text file. + """ + with fitz.open(pdf_path) as pdf_file: + text = "" + for page_index in range(len(pdf_file)): + page = pdf_file[page_index] + text += page.get_text() + + with open(output_path, "w", encoding="utf-8") as output_file: + output_file.write(text) + + print(f"PDF file converted to text and saved as '{output_path}'") + +def convert_pdf_to_images(pdf_path, output_folder): + """ + Convert a PDF file to individual image files. + """ + with fitz.open(pdf_path) as pdf_file: + for page_index in range(len(pdf_file)): + page = pdf_file[page_index] + image = page.get_pixmap() + image_path = os.path.join(output_folder, f"page_{page_index + 1}.png") + image.save(image_path) + + print(f"PDF file converted to images and saved in '{output_folder}'") + +def main(): + pdf_path = input("Enter the path to the PDF file: ") + conversion_type = input("Enter the conversion type ('text' or 'images'): ") + + if not os.path.exists(pdf_path): + print("The specified PDF file does not exist.") + return + + if conversion_type == "text": + output_path = os.path.splitext(pdf_path)[0] + ".txt" + convert_pdf_to_text(pdf_path, output_path) + elif conversion_type == "images": + output_folder = os.path.splitext(pdf_path)[0] + "_images" + os.makedirs(output_folder, exist_ok=True) + convert_pdf_to_images(pdf_path, output_folder) + else: + print("Invalid conversion type. Please choose 'text' or 'images'.") + +if __name__ == "__main__": + main() + + \ No newline at end of file diff --git a/SamridhiGupta/PDF_Converter/Readme.md b/SamridhiGupta/PDF_Converter/Readme.md new file mode 100644 index 0000000..bfe0be4 --- /dev/null +++ b/SamridhiGupta/PDF_Converter/Readme.md @@ -0,0 +1,52 @@ +# PDF Conversion Tool + +## Overview + +This Python program allows users to convert PDF files into either text files or individual image files. The program uses the `fitz` module from the PyMuPDF library to handle the PDF conversion. + +## Features + +- **PDF to Text Conversion**: Converts the entire content of a PDF file into a text file. +- **PDF to Images Conversion**: Converts each page of a PDF file into separate image files (PNG format). + +## Requirements + +- Python 3.x +- PyMuPDF library + +You can install PyMuPDF using pip: + +```sh +pip install pymupdf +``` + +## How to Use +1. Run the Program: Execute the script to start the program. +2. Provide PDF Path: Enter the path to the PDF file when prompted. +3. Choose Conversion Type: Enter either text or images to specify the type of conversion. + +## Example Usage + +1. **Convert PDF to Text:** +``` +Enter the path to the PDF file: example.pdf +Enter the conversion type ('text' or 'images'): text +PDF file converted to text and saved as 'example.txt' +``` +2. **Convert PDF to Images:** +``` +Enter the path to the PDF file: example.pdf +Enter the conversion type ('text' or 'images'): images +PDF file converted to images and saved in 'example_images' +``` +## Error Handling +The program includes basic error handling to manage common issues: + +1. **Non-existent PDF File:** + +If the specified PDF file does not exist, the program will display the message: The specified PDF file does not exist. +Invalid Conversion Type: + +2. **Invalid Conversion Type:** + +If the user enters a conversion type other than text or images, the program will display the message: Invalid conversion type. Please choose 'text' or 'images'. \ No newline at end of file diff --git a/SamridhiGupta/To-Do-List/Readme.md b/SamridhiGupta/To-Do-List/Readme.md new file mode 100644 index 0000000..a89cb03 --- /dev/null +++ b/SamridhiGupta/To-Do-List/Readme.md @@ -0,0 +1,92 @@ +# Task Management System + +## Overview + +This is a simple Python program to manage tasks. Users can add tasks, mark tasks as completed, delete tasks, and view all tasks with their completion status. + +## Features + +- **Add Task**: Allows the user to add a new task to the list. +- **Mark Task as Completed**: Allows the user to mark a specific task as completed. +- **Delete Task**: Allows the user to delete a specific task from the list. +- **Display All Tasks**: Displays all tasks along with their completion status. +- **Exit Program**: Allows the user to exit the program. + +## How to Use + +1. **Run the Program**: Execute the script to start the task management system. +2. **Choose an Option**: Follow the on-screen menu to choose an option by entering the corresponding number. +3. **Follow Prompts**: Enter the required information based on the chosen option (e.g., task details, task number). +4. **View Results**: The program will display appropriate messages based on the action performed. + +### Example Usage + +1. **Adding a Task**: + ``` + Task Management System + 1. Add a task + 2. Mark a task as completed + 3. Delete a task + 4. Display all tasks + 5. Exit + Enter your choice (1-5): 1 + Enter a new task: Buy groceries + Task added successfully. + ``` + +2. **Marking a Task as Completed**: + ``` + Task Management System + 1. Add a task + 2. Mark a task as completed + 3. Delete a task + 4. Display all tasks + 5. Exit + Enter your choice (1-5): 2 + Select a task to mark as completed: + 1. Buy groceries - Pending + Enter the task number: 1 + Task marked as completed. + ``` + +3. **Deleting a Task**: + ``` + Task Management System + 1. Add a task + 2. Mark a task as completed + 3. Delete a task + 4. Display all tasks + 5. Exit + Enter your choice (1-5): 3 + Select a task to delete: + 1. Buy groceries - Completed + Enter the task number: 1 + Task deleted successfully. + ``` + +4. **Displaying All Tasks**: + ``` + Task Management System + 1. Add a task + 2. Mark a task as completed + 3. Delete a task + 4. Display all tasks + 5. Exit + Enter your choice (1-5): 4 + All Tasks: + No tasks to display. + ``` +## Error Handling +The program includes basic error handling to manage common issues: + +1. **Empty Task List:** + +If there are no tasks to mark as completed, delete, or display, the program will display appropriate messages: No tasks to mark as completed., No tasks to delete., and No tasks to display. + +2. **Invalid Task Number:** + +If the user enters an invalid task number for marking as completed or deleting, the program will display the message: Invalid choice. + +3. **Invalid Menu Choice:** + +If the user enters a choice outside the range of 1-5, the program will display the message: Invalid choice. Please try again. \ No newline at end of file diff --git a/SamridhiGupta/To-Do-List/To_Do_List.py b/SamridhiGupta/To-Do-List/To_Do_List.py new file mode 100644 index 0000000..6e9098b --- /dev/null +++ b/SamridhiGupta/To-Do-List/To_Do_List.py @@ -0,0 +1,97 @@ +# Task Management System + +tasks = [] + +def display_menu(): + """ + Displays the menu for the user to choose an option. + """ + print("\nTask Management System") + print("1. Add a task") + print("2. Mark a task as completed") + print("3. Delete a task") + print("4. Display all tasks") + print("5. Exit") + +def add_task(): + """ + Prompts the user to enter a new task and adds it to the list. + """ + task = input("Enter a new task: ") + tasks.append({"task": task, "completed": False}) + print("Task added successfully.") + +def mark_completed(): + """ + Displays all tasks and prompts the user to select a task to mark as completed. + """ + if not tasks: + print("No tasks to mark as completed.") + return + + print("Select a task to mark as completed:") + for i, task in enumerate(tasks, start=1): + print(f"{i}. {task['task']} - {'Completed' if task['completed'] else 'Pending'}") + + choice = int(input("Enter the task number: ")) + if 1 <= choice <= len(tasks): + tasks[choice - 1]['completed'] = True + print("Task marked as completed.") + else: + print("Invalid choice.") + +def delete_task(): + """ + Displays all tasks and prompts the user to select a task to delete. + """ + if not tasks: + print("No tasks to delete.") + return + + print("Select a task to delete:") + for i, task in enumerate(tasks, start=1): + print(f"{i}. {task['task']} - {'Completed' if task['completed'] else 'Pending'}") + + choice = int(input("Enter the task number: ")) + if 1 <= choice <= len(tasks): + del tasks[choice - 1] + print("Task deleted successfully.") + else: + print("Invalid choice.") + +def display_tasks(): + """ + Displays all tasks with their completion status. + """ + if not tasks: + print("No tasks to display.") + return + + print("All Tasks:") + for i, task in enumerate(tasks, start=1): + print(f"{i}. {task['task']} - {'Completed' if task['completed'] else 'Pending'}") + +def main(): + """ + The main function that runs the program. + """ + while True: + display_menu() + choice = input("Enter your choice (1-5): ") + + if choice == "1": + add_task() + elif choice == "2": + mark_completed() + elif choice == "3": + delete_task() + elif choice == "4": + display_tasks() + elif choice == "5": + print("Exiting the program. Goodbye!") + break + else: + print("Invalid choice. Please try again.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/SamridhiGupta/Weather_App/Readme.md b/SamridhiGupta/Weather_App/Readme.md new file mode 100644 index 0000000..7179868 --- /dev/null +++ b/SamridhiGupta/Weather_App/Readme.md @@ -0,0 +1,45 @@ +# Weather Information + +## Overview + +This Python program fetches and displays current weather information for a specified city using the OpenWeatherMap API. It provides details such as temperature, humidity, wind speed, and a brief description of the weather. + +## Features + +- **Fetch Weather Data**: Retrieves current weather data from the OpenWeatherMap API for a specified city. +- **Display Weather Information**: Displays the fetched weather information in a readable format. + +## How to Use + +1. **Enter a City Name**: When prompted, enter the name of the city for which you want to get the weather information. +2. **View Results**: The program will display the current weather conditions for the specified city. + +### Example Usage + +1. **Entering a City Name**: + ``` + Enter the name of a city: London + ``` + +2. **Viewing Weather Information**: + ``` + Current weather in London: + Description: clear sky + Temperature: 15.0°C + Humidity: 72% + Wind speed: 3.5 m/s + ``` +## Error Handling +The program includes basic error handling to manage common issues: + +1. **Invalid API Key:** + +If the API key is invalid or missing, the program will display an error message: Error: 401 - {"cod":401,"message":"Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."} + +2. **City Not Found:** + +If the specified city is not found, the program will display an error message: Error: 404 - {"cod":"404","message":"city not found"} + +3. **Network Issues:** + +If there are network issues or the API endpoint is unreachable, the program will display an appropriate error message: Error: - diff --git a/SamridhiGupta/Weather_App/Weather.py b/SamridhiGupta/Weather_App/Weather.py new file mode 100644 index 0000000..028b0f9 --- /dev/null +++ b/SamridhiGupta/Weather_App/Weather.py @@ -0,0 +1,44 @@ +import requests + +API_ENDPOINT = "https://api.openweathermap.org/data/2.5/weather" +API_KEY = "4e3bb6b4c5a92eaabcfef739e346e861" +# Function to get weather data from the API +def get_weather_data(city): + + url = f"{API_ENDPOINT}?q={city}&appid={API_KEY}&units=metric" + + response = requests.get(url) + + if response.status_code == 200: + return response.json() + else: + print(f"Error: {response.status_code} - {response.text}") + return None + +# Function to display weather information +def display_weather_info(weather_data): + + if weather_data: + # Get relevant data from the weather dictionary + city_name = weather_data["name"] + weather_description = weather_data["weather"][0]["description"] + temperature = weather_data["main"]["temp"] + humidity = weather_data["main"]["humidity"] + wind_speed = weather_data["wind"]["speed"] + + # Display current weather conditions + print(f"Current weather in {city_name}:") + print(f"Description: {weather_description}") + print(f"Temperature: {temperature}°C") + print(f"Humidity: {humidity}%") + print(f"Wind speed: {wind_speed} m/s") + else: + print("No weather data available.") + +def main(): + city = input("Enter the name of a city: ") + weather_data = get_weather_data(city) + display_weather_info(weather_data) + +if __name__ == "__main__": + main() \ No newline at end of file