Giter Club home page Giter Club logo

python-project-20's Introduction

20 Python Project ๐Ÿš€

1. Email Sender ๐Ÿ“ง

The main.py script demonstrates how to send an email using Gmail's SMTP server securely. The script utilizes the smtplib library for SMTP communication and the ssl library for creating a secure context.

Functionality โš™๏ธ

  1. Import Libraries โ–ถ๏ธ

    • Imports necessary libraries such as sys, ssl, smtplib, EmailMessage, and the custom helpers module.
  2. Set Email Configuration ๐Ÿ“ง

    • Sets up the email configuration, including the sender's email address (emailSender), receiver's email address (emailReceiver), subject of the email (subject), and the email body (body).
  3. Read App Password ๐Ÿ”

    • Reads the Gmail app password from the config.json file using the readJson function from the custom helpers module.
  4. Compose Email โœ๏ธ

    • Creates an instance of the EmailMessage class and sets its properties, including sender, receiver, subject, and body.
  5. Secure Connection ๐Ÿ”’

    • Establishes a secure connection to Gmail's SMTP server using the smtplib.SMTP_SSL class.
  6. Login to Email Account ๐Ÿ”‘

    • Logs in to the sender's Gmail account using the provided email address (emailSender) and app password (emailPassword).
  7. Send Email ๐Ÿ“ซ

    • Sends the composed email using the smtp.sendmail method.
  8. Print Success Message โœ…

    • Prints "Email sent successfully!" to the console if the email is sent without errors.

Usage ๐Ÿ”ง

  1. Update the script with your Gmail sender email address, receiver email address, and Gmail app password.
  2. Run the script using python main.py.
  3. Check the console for the success message.

2. Word Replacement Function โœ๏ธ

The replaceWord function demonstrates a simple word replacement mechanism in a string.

Functionality โš™๏ธ

  1. Initialize String ๐Ÿ“„

    • Initializes a string with the content "Anjasfedo hi hi hi hi hi".
  2. Get User Input for Word Replacement โŒจ๏ธ

    • Takes user input for the word to be replaced using the input function.
  3. Get User Input for Word Replacement โŒจ๏ธ

    • Takes user input for the replacement word using the input function.
  4. Replace Word in String ๐Ÿ”„

    • Uses the replace method to replace occurrences of the specified word with the replacement word in the string.
  5. Return Modified String โžก๏ธ

    • Returns the modified string after the word replacement.
  6. Print Modified String ๐Ÿ“ƒ

    • Prints the result of the replaceWord function, showcasing the string after word replacement.

Usage ๐Ÿ”ง

  1. Modify the initial string or run the function as is to see the word replacement in action.

3. Simple Calculator :123:

The arithmeticOperation module contains functions for basic arithmetic operations.

Functionality โš™๏ธ

  1. Addition โž•

    • Adds two numbers and prints the result.
  2. Subtraction โž–

    • Subtracts the second number from the first and prints the result.
  3. Multiplication โœ–๏ธ

    • Multiplies two numbers and prints the result.
  4. Division โž—

    • Divides the first number by the second (with error handling for division by zero) and prints the result or an error message.

Usage ๐Ÿ”ง

  1. Modify the numbers in the function calls or run the functions as is to perform basic arithmetic operations.

4. Email Slicer โœ‚๏ธ

The main.py script slices an email address into its components, including the username, domain, and extension.

Functionality โš™๏ธ

  1. Display Welcome Message ๐Ÿ‘‹

    • Displays a welcome message and instructions to close the program.
  2. User Input for Email Address โŒจ๏ธ

    • Takes user input for the email address.
  3. Slice Email Components โœ‚๏ธ

    • Slices the email address into username, domain, and extension.
  4. Print Sliced Components ๐Ÿ“ƒ

    • Prints the sliced components of the email address.

Usage ๐Ÿ”ง

  1. Run the script using python main.py.
  2. Input your email address when prompted.
  3. View the sliced components displayed on the console.

5. Binary Search Algorithm ๐Ÿ”Ž

The binarySearch function demonstrates a binary search algorithm to find an element in a sorted list.

Functionality โš™๏ธ

  1. Binary Search Function :arrow_binary:

    • The main binary search function that takes a sorted list (myList) and an element to search for (element).
  2. Initialize variables ๐Ÿ”ข

    • middle, start, and end represent indices, and steps counts the iterations.
  3. Iterate while the search range is valid ๐Ÿ”„

    • The while loop continues until the start index is greater than the end index.
  4. Display the current search range ๐Ÿ“œ

    • Prints the current sub-list being considered in each iteration.
  5. Update step count and calculate middle index ๐Ÿ”ข

    • Increments the step count and calculates the middle index of the current range.
  6. Check if the element is found โœ…

    • Compares the middle element with the target element and returns the index if found.
  7. Update the start and end based on element comparison ๐Ÿ”„

    • If the target element is less than the middle, updates the end index; if greater, updates the start index.
  8. If the element is not found โš ๏ธ

    • Prints a message indicating that the element is not present in the list.

Usage ๐Ÿ”ง

  1. Calls the binarySearch function with an example list and element and prints the result.
  2. Run the script using python main.py.

6. Quiz Program โ“

The main.py script implements a simple quiz program using questions stored in the questions.py module.

Functionality โš™๏ธ

  1. Quiz Loop ๐Ÿ”

    • Iterates through each question in the quiz.
  2. Display Question ๐Ÿ’ฌ

    • Prints the current question.
  3. User Input for Answer โŒจ๏ธ

    • Takes user input for the answer.
  4. Check Answer โœ…

    • Compares the user's answer with the correct answer.
  5. Score Tracking ๐Ÿ”ข

    • Updates the user's score based on correct answers.
  6. Display Results ๐Ÿ†

    • Prints whether each answer is correct or wrong.
    • Displays the final score at the end of the quiz.

Usage ๐Ÿ”ง

  1. Run the script using python main.py.
  2. Answer each quiz question prompted.
  3. View the correctness of your answers and your final score at the end.

7. QR Code Generator โฌœโฌ›โฌœ

The main.py script generates a QR code for a given URL using the qrcode library.

Functionality โš™๏ธ

  1. Import Libraries โ–ถ๏ธ

    • Imports necessary libraries, including qrcode and os.
  2. Generate QR Code :barcode:

    • Utilizes the qrcode library to create a QR code for a given URL.
    • The os library is used to handle directory operations.
  3. Save QR Code Image ๐Ÿ’พ

    • The generated QR code image is saved in the images directory.
    • The directory is created if it doesn't exist.
  4. Display Image Path ๐Ÿ“

    • Prints the path where the QR code image is saved.

Usage ๐Ÿ”ง

  1. Run the script using python main.py.
  2. Enter the URL when prompted.
  3. Check the images directory for the saved QR code image.

8. Interest Payment Calculator ๐Ÿ’ฑ

The main.py script calculates the monthly payment for a loan based on the loan amount, annual interest rate, and the number of years.

Functionality โš™๏ธ

  1. Display Welcome Message ๐Ÿ‘‹

    • Displays a welcome message introducing the monthly payment loan calculator.
  2. User Input for Loan Details โŒจ๏ธ

    • Takes user input for the loan amount, annual interest rate, and the number of years.
  3. Calculate Monthly Interest Rate ๐Ÿ”ข

    • Calculates the monthly interest rate based on the annual interest rate.
  4. Calculate Total Number of Months ๐Ÿ“†

    • Calculates the total number of months for the loan based on the number of years.
  5. Calculate Monthly Payment ๐Ÿ’ธ

    • Uses the loan formula to calculate the monthly payment.
  6. Display Monthly Payment ๐Ÿ’ป

    • Prints the calculated monthly payment with 2 decimal places on the console.
  7. Save Result to Text File ๐Ÿ’พ

    • Saves the calculated monthly payment to a text file named "interest_payment_calculator_result.txt" inside the "texts" directory.

Usage ๐Ÿ”ง

  1. Run the script using python main.py.
  2. Input the loan amount, annual interest rate, and the number of years when prompted.
  3. View the calculated monthly payment on the console.
  4. Check the "texts/interest_payment_calculator_result.txt" file for the saved result.

9. Password Generator ๐Ÿ”‘

The password_generator.py script generates a random password based on user input and saves it to a text file.

Functionality โš™๏ธ

  1. Generate Password ๐Ÿ”‘

    • Asks the user for the desired length of the password.
    • Creates a random password using a combination of uppercase letters, lowercase letters, digits, and special characters.
    • Shuffles the characters to add randomness to the password.
    • Displays the generated password on the console.
  2. Save Password to Text File ๐Ÿ’พ

    • Saves the generated password to a text file named "password.txt" in the "texts" directory.
    • Creates the "texts" directory if it doesn't exist.
  3. User Interaction ๐Ÿ’ป

    • Asks the user if they want to generate a password.
    • Ends the program if the user chooses not to generate a password.

Usage ๐Ÿ”ง

  1. Run the script using python main.py.
  2. Input the desired length of the password when prompted.
  3. View the generated password on the console.
  4. Check the "texts" directory for the saved password in the "password.txt" file.

10. Dice Rolling ๐ŸŽฒ

The main.py script simulates rolling two six-sided dice and displays the results using ASCII art.

Functionality โš™๏ธ

  1. Dice Representation ๐ŸŽจ

    • Defines ASCII art representations for each possible face of a six-sided die.
    • ASCII art is stored in a dictionary (diceDrawing) with keys representing the numbers 1 to 6.
  2. Roll Dice Function ๐ŸŽฒ

    • Prompts the user if they want to roll the dice.
    • Continues rolling as long as the user responds with 'Yes'.
    • Generates random numbers for two dice rolls.
    • Displays the result of the dice rolls and the corresponding ASCII art.
    • Prompts the user if they want to roll again.
  3. Random Number Generation ๐ŸŽฒ

    • Utilizes the random module to generate random numbers for dice rolls.

Usage ๐Ÿ”ง

  1. Run the script using python main.py.
  2. Input 'Yes' when prompted to roll the dice.
  3. View the results of the dice rolls and corresponding ASCII art.
  4. Choose to roll again or end the program.

11. Site Connectivity Checker ๐ŸŒ

The main.py script checks the connectivity of a specified website by attempting to open a connection to the provided URL.

Functionality โš™๏ธ

  1. Main Function ๐Ÿ”Ž

    • Defines a function named main that takes a URL as a parameter.
    • Opens a connection to the specified URL using urllib.urlopen.
    • Displays a message indicating successful connection along with the response code.
  2. Site Connectivity Check ๐ŸŒ

    • Prompts the user to input the domain of the site (e.g., "google.com").
    • Constructs a full URL by adding "https://www." as a prefix to the user-provided domain.
    • Calls the main function, passing the constructed full URL, to check the site's connectivity.

Usage ๐Ÿ”ง

  1. Run the script using python main.py.
  2. Input the domain of the site when prompted.
  3. View the messages indicating the site's connectivity and response code.

12. Currency Converter :money_exchange:

The main.py script converts US dollars to Pound Sterling using a fixed exchange rate.

Functionality โš™๏ธ

  1. Main Function ๐Ÿ’ธ

    • Defines a function named main.
    • Displays a message indicating the purpose of the script.
    • Prompts the user to input a dollar amount using eval to evaluate the input as a Python expression.
    • Calls the convert_to_pounds function to convert dollars to pounds.
    • Displays the result of the conversion.
  2. Conversion Function ๐Ÿ’ฑ

    • Uses a lambda function named convert_to_pounds to convert dollars to pounds using a fixed exchange rate.

Usage ๐Ÿ”ง

  1. Run the script using python main.py.
  2. Input the dollar amount when prompted.
  3. View the converted amount in pounds sterling.

13. Leap Year Checker ๐Ÿ“…

The is_leap_year function checks if a given year is a leap year or not.

Functionality โš™๏ธ

  1. Leap Year Checking ๐Ÿ“†
    • The function takes a year as an argument.
    • Checks if the year is divisible by 4.
    • If divisible by 4, it further checks if it is divisible by 100.
      • If divisible by 100, it checks if it is divisible by 400.
        • If divisible by 400, prints "Leap year."
        • If not divisible by 400, prints "Not leap year."
      • If not divisible by 100, prints "Leap year."
    • If not divisible by 4, prints "Not leap year."

Usage ๐Ÿ”ง

  1. Call the function is_leap_year with the desired year as an argument.
    is_leap_year(2000)
  2. The function will print whether the given year is a leap year or not. Example Output: "Leap year" (for the year 2000)

14. Word Meaning Checker ๐Ÿ“–

The script utilizes the PyDictionary library to retrieve the meaning of a given word.

Functionality โš™๏ธ

  1. Import PyDictionary ๐Ÿ“–

    • Imports the PyDictionary class from the PyDictionary module.
  2. Create PyDictionary Instance ๐Ÿญ

    • Creates an instance of the PyDictionary class named dictionaries.
  3. Input Loop ๐Ÿ”

    • Initiates an infinite loop using while True.
  4. User Input for Word โŒจ๏ธ

    • Prompts the user to enter a word.
  5. Check for Empty Input โœ…

    • Checks if the entered word is an empty string.
      • If empty, exits the loop.
  6. Retrieve and Display Meaning ๐Ÿ”

    • Uses the meaning method of the PyDictionary class to retrieve the meaning of the entered word.
    • Prints the meaning to the console.

Usage ๐Ÿ”ง

  1. Run the script and input a word when prompted.
  2. View the meaning of the entered word on the console.
  3. To exit the loop, simply press Enter without typing a word.

Helpers

Helpers Function for Reading JSON Configuration ๐Ÿ“

The readJson function serves as a helper to read values from a JSON configuration file.

Functionality โš™๏ธ

  1. Read JSON Configuration ๐Ÿ“

    • Takes two parameters: path for the path to the JSON file and value for the key to retrieve.
    • Uses the open function to open the specified JSON file in read mode.
    • Utilizes json.load to load the JSON content from the file.
  2. Retrieve Specific Value โžก๏ธ

    • Returns the value associated with the specified key (value) in the JSON file.
  3. Error Handling โš ๏ธ

    • The function assumes that the key (value) exists in the JSON file. Error handling can be added to handle cases where the key is not present.

Usage ๐Ÿ”ง

  1. Configure JSON File โœ๏ธ

    • Ensure that the config.json file is properly configured with the required key-value pairs. For example:
      {
        "GMAIL_APP_PASSWORD": "your_gmail_app_password"
      }
  2. Use readJson Function ๐Ÿ“ฒ

    • Call the readJson function in your main script to retrieve specific values from the configuration file.

         # Example usage in the main script
         email_password = readJson("path/to/config.json", "GMAIL_APP_PASSWORD")

python-project-20's People

Contributors

anjasfedo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.