{"id":23436,"date":"2023-01-08T20:38:55","date_gmt":"2023-01-08T15:08:55","guid":{"rendered":"https:\/\/tocxten.com\/?page_id=23436"},"modified":"2023-03-19T01:07:09","modified_gmt":"2023-03-18T19:37:09","slug":"sample-python-projects","status":"publish","type":"page","link":"https:\/\/tocxten.com\/index.php\/sample-python-projects\/","title":{"rendered":"Sample Python Projects"},"content":{"rendered":"\n<p class=\"has-cyan-bluish-gray-background-color has-background\" style=\"font-size:24px\"><strong>Project 1 : Guess the number Game<\/strong><\/p>\n\n\n\n<p>Guess the number is a simple game where the player tries to guess a random number within a certain range.<\/p>\n\n\n\n<p class=\"has-light-green-cyan-background-color has-background\"><strong>Source Code : <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"599\" src=\"https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-1-1024x599.png\" alt=\"\" class=\"wp-image-23438\" srcset=\"https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-1-1024x599.png 1024w, https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-1-300x175.png 300w, https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-1-768x449.png 768w, https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-1-760x445.png 760w, https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-1-600x351.png 600w, https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-1.png 1048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-light-green-cyan-background-color has-background\"><strong>Output : <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-2.png\" alt=\"\" class=\"wp-image-23439\" width=\"466\" height=\"445\" srcset=\"https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-2.png 627w, https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-2-300x286.png 300w, https:\/\/tocxten.com\/wp-content\/uploads\/2023\/01\/image-2-600x572.png 600w\" sizes=\"auto, (max-width: 466px) 100vw, 466px\" \/><\/figure>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\" style=\"font-size:24px\"><strong>Project 2 : <\/strong>Password Generator <\/p>\n\n\n\n<p>A password generator is a program that automatically creates strong, random passwords that are difficult for others to guess or crack. [ Source : https:\/\/www.freecodecamp.org\/news\/python-program-examples-simple-code-examples-for-beginners\/amp\/ ]<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#cfe1d0\"><strong>Source Code : <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\r\nimport string\r\n\r\ndef generate_password(length):\r\n    \"\"\"This function generates a random password\r\n    of a given length using a combination of\r\n    uppercase letters, lowercase letters,\r\n    digits, and special characters\"\"\"\r\n    \r\n    # Define a string containing all possible characters\r\n    all_chars = string.ascii_letters + string.digits + string.punctuation\r\n    \r\n    # Generate a password using a random selection of characters\r\n    password = \"\".join(random.choice(all_chars) for i in range(length))\r\n    \r\n    return password\r\n\r\n# Test the function by generating a password of length 10\r\npassword = generate_password(10)\r\nprint(password<\/code><\/pre>\n\n\n\n<p class=\"has-background\" style=\"background-color:#c7d2c0\"><strong>Sample Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Output1: \nq&lt;he$,7gj\/\n#output2:\n&amp;X#O+*ij0_\n#Output3:\nnSj]>V!b59\n#Output4:\n9K:qE\\PTU><\/code><\/pre>\n\n\n\n<p class=\"has-background\" style=\"background-color:#d0dfe5;font-size:24px\"><strong>Project 3: <\/strong>Password Checker<\/p>\n\n\n\n<p>A password checker is a program that evaluates the strength of a password based on certain criteria, such as length, complexity, and uniqueness. [ Source : https:\/\/www.freecodecamp.org\/news\/python-program-examples-simple-code-examples-for-beginners\/amp\/ ]<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#d5e8c8\"><strong>Source Code :<\/strong> <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Define a function to check if the password is strong enough\r\ndef password_checker(password):\r\n    # Define the criteria for a strong password\r\n    min_length = 8\r\n    has_uppercase = False\r\n    has_lowercase = False\r\n    has_digit = False\r\n    has_special_char = False\r\n    special_chars = \"!@#$%^&amp;*()-_=+&#91;{]}\\|;:',&lt;.>\/?\"\r\n    \r\n    # Check the length of the password\r\n    if len(password) &lt; min_length:\r\n        print(\"Password is too short!\")\r\n        return False\r\n    \r\n    # Check if the password contains an uppercase letter, lowercase letter, digit, and special character\r\n    for char in password:\r\n        if char.isupper():\r\n            has_uppercase = True\r\n        elif char.islower():\r\n            has_lowercase = True\r\n        elif char.isdigit():\r\n            has_digit = True\r\n        elif char in special_chars:\r\n            has_special_char = True\r\n    \r\n    # Print an error message for each missing criteria\r\n    if not has_uppercase:\r\n        print(\"Password must contain at least one uppercase letter!\")\r\n        return False\r\n    if not has_lowercase:\r\n        print(\"Password must contain at least one lowercase letter!\")\r\n        return False\r\n    if not has_digit:\r\n        print(\"Password must contain at least one digit!\")\r\n        return False\r\n    if not has_special_char:\r\n        print(\"Password must contain at least one special character!\")\r\n        return False\r\n    \r\n    # If all criteria are met, print a success message\r\n    print(\"Password is strong!\")\r\n    return True\r\n\r\n# Prompt the user to enter a password and check if it meets the criteria\r\npassword = input(\"Enter a password: \")\r\npassword_checker(password)<\/code><\/pre>\n\n\n\n<p class=\"has-background\" style=\"background-color:#d6dfcf\"><strong>Sample Output : <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>#Output1<\/strong>\nEnter a password: $%^&amp;2348971\r\nPassword must contain at least one uppercase letter!\r\nFalse\n<strong>#Ouput2 <\/strong>\nEnter a password: abc!@#767Thy\r\nPassword is strong!\r\nTrue\n<strong>#Ouput3<\/strong>\nEnter a password: abcdefghi\r\nPassword must contain at least one uppercase letter!\r\nFalse<\/code><\/pre>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\" style=\"font-size:24px\"><strong>Project 4: Web Scrapping Links form a given website<\/strong><\/p>\n\n\n\n<p>Web scraping is the process of extracting data from websites using automated methods. Here are the basic steps to perform web scraping using Python:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Choose a website to scrape: Identify the website from which you want to extract data.<\/li><li>Inspect the website: Use the web browser&#8217;s developer tools to inspect the website and identify the HTML elements that contain the data you want to extract.<\/li><li>Install the necessary libraries: You can use Python libraries like <code>requests<\/code> and <code>BeautifulSoup<\/code> to extract data from websites. Install them by running <code>pip install requests<\/code> and <code>pip install beautifulsoup4<\/code> in the command line.<\/li><li>Send an HTTP request: Use the <code>requests<\/code> library to send an HTTP request to the website and retrieve the HTML content.<\/li><li>Parse the HTML content: Use the <code>BeautifulSoup<\/code> library to parse the HTML content and extract the data you want.<\/li><li>Extract the data: Once you have identified the HTML elements that contain the data you want, you can extract it using methods like <code>.text<\/code>, <code>.get()<\/code>, <code>.find_all()<\/code>, or <code>.select()<\/code>.<\/li><li>Store or process the data: You can store the extracted data in a file or database, or process it further in your Python program.<\/li><\/ol>\n\n\n\n<p>Note: Be sure to review the website&#8217;s terms of use and robots.txt file to ensure that web scraping is allowed and to avoid overloading the website&#8217;s servers. Also, be sure to respect the website&#8217;s copyright and intellectual property rights.<\/p>\n\n\n\n<p>A web scraper scrapes\/gets data from webpages and saves it in any format we want, either .csv or .txt. We will build a simple web scraper in this section using a Python library called Beautiful Soup. [ Source : https:\/\/www.freecodecamp.org\/news\/python-program-examples-simple-code-examples-for-beginners\/amp\/ ]<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#d7e3d3\"><strong>Source Code :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import requests\r\nfrom bs4 import BeautifulSoup\r\n\r\n# Set the URL of the webpage you want to scrape\r\nurl = 'https:\/\/www.tocxten.com'\r\n\r\n# Send an HTTP request to the URL and retrieve the HTML content\r\nresponse = requests.get(url)\r\n\r\n# Create a BeautifulSoup object that parses the HTML content\r\nsoup = BeautifulSoup(response.content, 'html.parser')\r\n\r\n# Find all the links on the webpage\r\nlinks = soup.find_all('a')\r\n\r\n# Print the text and href attribute of each link\r\nfor link in links:\r\n    print(link.get('href'), link.text)<\/code><\/pre>\n\n\n\n<p class=\"has-background\" style=\"background-color:#dbebd8\"><strong>Output :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#textwp-posts-wrapper Skip to content\r\nhttps:&#47;&#47;tocxten.com\/ \r\nhttps:\/\/tocxten.com\/ HOME\r\nhttps:\/\/tocxten.com\/index.php\/privacy-policy\/ ABOUT\r\nhttps:\/\/tocxten.com\/ Current Context\r\n<a class=\"twitter-timeline\" data-width=\"500\" data-height=\"750\" data-dnt=\"true\" href=\"https:\/\/twitter.com\/tocxten?ref_src=twsrc%5Etfw\">Tweets by tocxten<\/a><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script> \r\nhttps:\/\/www.facebook.com\/tocx.ten \r\nhttps:\/\/www.linkedin.com\/in\/tocxten-ai-bb311a1b9\/ \r\nhttps:\/\/www.youtube.com\/channel\/UCEwvOli0KZVgzn-QQekv6uw \r\n<div class=\"github-embed github-embed-user github-logo-octocat\">\t<p>\t\t<a href=\"https:\/\/github.com\/TOCXTEN-AI\" target=\"_blank\">\t\t\t<strong>\t\t\t\tTOCXTEN-AI\t\t\t<\/strong>\t\t<\/a>\t\t<br>\t\t0 repositories, 0 followers.\t<\/p><\/div> \r\nmailto:tocxten@gmail.com \r\nhttps:\/\/tocxten.com\/wp-login.php?redirect_to=https%3A%2F%2Ftocxten.com%2Findex.php%2F2023%2F03%2F12%2Fintroduction-to-python-programming-python-basics-1-0%2F \r\n# \r\nhttps:\/\/tocxten.com\/index.php\/2023\/03\/12\/introduction-to-python-programming-python-basics-1-0\/<\/code><\/pre>\n\n\n\n<p class=\"has-background\" style=\"background-color:#d4e0d1;font-size:24px\"><strong>Project 5: Currency Converter <\/strong><\/p>\n\n\n\n<p>A currency converter is a program that helps users convert the value of one currency into another currency. You can use it for a variety of purposes, such as calculating the cost of international purchases, estimating travel expenses, or analyzing financial data. Note: we will use the ExchangeRate-API to get the exchange rate data, which is a free and open-source API for currency exchange rates. But there are other APIs available that may have different usage limits or requirements. [ Source : https:\/\/www.freecodecamp.org\/news\/python-program-examples-simple-code-examples-for-beginners\/amp\/ ]<\/p>\n\n\n\n<p>Here&#8217;s an example of how to create a currency converter using Python:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Install the requests library: You can use the <code>requests<\/code> library to retrieve the latest exchange rates from a public API. Install the library by running <code>pip install requests<\/code> in the command line.<\/li><li>Retrieve the exchange rates: Use the <code>requests<\/code> library to retrieve the latest exchange rates from a public API. For example, you can use the <code>fixer.io<\/code> API, which provides exchange rates for a variety of currencies. To retrieve the exchange rates, send an HTTP GET request to the API endpoint, passing in your API access key and the base currency you want to convert from. <\/li><li>Implement the currency conversion function: Write a function that takes in the amount to convert, the currency to convert from, and the currency to convert to, and returns the converted amount. To convert the currency, multiply the amount by the exchange rate for the target currency.<\/li><li>Implement the user interface: Create a simple user interface that prompts the user to enter the amount to convert, the currency to convert from, and the currency to convert to, and displays the converted amount.<\/li><li>Test the program: Test the program by entering various amounts and currency conversions and verifying that the converted amounts are accurate.<\/li><\/ol>\n\n\n\n<p class=\"has-background\" style=\"background-color:#cce3cb\"><strong>Source Code : <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Import the necessary modules\r\nimport requests\r\n\r\n# Define a function to convert currencies\r\ndef currency_converter(amount, from_currency, to_currency):\r\n    # Set the API endpoint for currency conversion\r\n    api_endpoint = f\"https:\/\/api.exchangerate-api.com\/v4\/latest\/{from_currency}\"\r\n    \r\n    # Send a GET request to the API endpoint\r\n    response = requests.get(api_endpoint)\r\n    \r\n    # Get the JSON data from the response\r\n    data = response.json()\r\n    \r\n    # Extract the exchange rate for the target currency\r\n    exchange_rate = data&#91;\"rates\"]&#91;to_currency]\r\n    \r\n    # Calculate the converted amount\r\n    converted_amount = amount * exchange_rate\r\n    \r\n    # Return the converted amount\r\n    return converted_amount\r\n\r\n# Prompt the user to enter the amount, source currency, and target currency\r\namount = float(input(\"Enter the amount: \"))\r\nfrom_currency = input(\"Enter the source currency code: \").upper()\r\nto_currency = input(\"Enter the target currency code: \").upper()\r\n\r\n# Convert the currency and print the result\r\nresult = currency_converter(amount, from_currency, to_currency)\r\nprint(f\"{amount} {from_currency} is equal to {result} {to_currency}\")<\/code><\/pre>\n\n\n\n<p class=\"has-background\" style=\"background-color:#d1e1d1\"><strong>Sample Output : <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the amount: 100\r\nEnter the source currency code: USD\r\nEnter the target currency code: INR\r\n100.0 USD is equal to 8264.0 INR<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Project 1 : Guess the number Game Guess the number is a simple game where the player tries to guess a random number within a certain range. Source Code :&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-23436","page","type-page","status-publish","hentry"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/23436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/comments?post=23436"}],"version-history":[{"count":18,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/23436\/revisions"}],"predecessor-version":[{"id":24387,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/23436\/revisions\/24387"}],"wp:attachment":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/media?parent=23436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}