Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Beginner Level #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions SamridhiGupta/Calculator/Calculator.py
Original file line number Diff line number Diff line change
@@ -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()
63 changes: 63 additions & 0 deletions SamridhiGupta/Calculator/Readme.md
Original file line number Diff line number Diff line change
@@ -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
```

34 changes: 34 additions & 0 deletions SamridhiGupta/Number_Game/Number_Game.py
Original file line number Diff line number Diff line change
@@ -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()
49 changes: 49 additions & 0 deletions SamridhiGupta/Number_Game/Readme.md
Original file line number Diff line number Diff line change
@@ -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.
53 changes: 53 additions & 0 deletions SamridhiGupta/PDF_Converter/PDF_Converter.py
Original file line number Diff line number Diff line change
@@ -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()


52 changes: 52 additions & 0 deletions SamridhiGupta/PDF_Converter/Readme.md
Original file line number Diff line number Diff line change
@@ -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'.
92 changes: 92 additions & 0 deletions SamridhiGupta/To-Do-List/Readme.md
Original file line number Diff line number Diff line change
@@ -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.
Loading