May 28, 2021 Article blog
Python is powerful enough to be applied to every corner of your life, and here are five small projects that are widely used.
Goal: Write a Python script that gets the username and domain name from the email address
Tips: Divide the address into 2 strings using the s as a separator
Goal: Make a script that automatically sends e-mail messages
Tips:email libraries can be used to send e-mail messages.
import smtplib
from email.message import EmailMessage
email = EmailMessage() ## Creating a object for EmailMessage
email['from'] = 'xyz name' ## Person who is sending
email['to'] = 'xyz id' ## Whom we are sending
email['subject'] = 'xyz subject' ## Subject of email
email.set_content("Xyz content of email") ## content of email
with smtlib.SMTP(host='smtp.gmail.com',port=587)as smtp:
## sending request to server
smtp.ehlo() ## server object
smtp.starttls() ## used to send data between server and client
smtp.login("email_id","Password") ## login id and password of gmail
smtp.send_message(email) ## Sending email
print("email send") ## Printing success message
Goal: Make a script that generates abbreviations for a given sentence
Tips: You can index and split to get the first word and then combine it
Goal: Make an interesting adventure for users by choosing different options through the path
Goal: Make a command-line Hangman game
Tips: Create a list of cryptographic words and randomly select a word, underline each word with an underlined """
import time
import random
name = input("What is your name? ")
print ("Hello, " + name, "Time to play hangman!")
time.sleep(1)
print ("Start guessing...\n")
time.sleep(0.5)
## A List Of Secret Words
words = ['python','programming','treasure','creative','medium','horror']
word = random.choice(words)
guesses = ''
turns = 5
while turns > 0:
failed = 0
for char in word:
if char in guesses:
print (char,end="")
else:
print ("_",end=""),
failed += 1
if failed == 0:
print ("\nYou won")
break
guess = input("\nguess a character:")
guesses += guess
if guess not in word:
turns -= 1
print("\nWrong")
print("\nYou have", + turns, 'more guesses')
if turns == 0:
print ("\nYou Lose")
That's all you'll find out about Python's five mini-projects.