5 classic projects suitable for Python practice, interesting and practical, must-see if you want to get started and get a high salary!
foreword
Hello fellow Baidu friends! I'm Skye!
I hope that through my sharing, I can bring some positive energy to everyone. Friends who are on the edge of giving up have seen it, and those who can continue to persevere and work hard have seen it and become better!
Not much nonsense, the following is the real information + sharing, please read it patiently.
1. Automatically send emails
Write a script in Python that can send emails.
Tip: The email library can be used to send emails.
import email
from email.message import EmailMessage
email = EmailMessage() ## Creating an 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.gamil.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
2. Hangman (a game of guessing words)
Create a simple hangman guessing word game in Python.
Tip: Create a list of passwords and choose a word at random. Indicate each word with an underscore "" and let the user guess the word, and if the user guesses correctly, replace the "" with the word.
import time
import random
name = input("What is your name?")
time.sleep(1)
print ("Start guessing...\n")
time.sleep(0.5)
## A list Of Secret Words
words = ["python","programming","treasure","creative","medium","horror"]
words = random.choice(words)
guesses = ''
turns = 5
import 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:")
guess += guess
if guess not in word
turns -= 1
print("\nWrong")
print("\nYou have",) + turns,'more guesses'
if turns == 0
print ("\nYou Lose")
3. Alarm clock
Write a script in Python that creates an alarm clock.
Tip: Use the date-time module to create an alarm, then use the playsound library to play the sound.
from datetime import datetime
from playsound import playsound
alarm_time = input("Enter the time of alarm to be set:HH:MM:SS\n")
alarm_hour=alarm_time[0:2]
alarm_minute=alarm_time[3:5]
alarm_seconds=alarm_time[6:8]
alarm_period = alarm_time[9:11].upper()
print("Setting up alarm..")
while True:
now = datetime.now()
current_hour = now.strftime("%I")
current_minute = now.strftime("%M")
current_seconds = now.strftime("%S")
current_period = now.strftime("%p")
if(alarm_period==current_period):
if(alarm_hour==current_hour):
if(alarm_minute==current_minute):
if(alarm_seconds==current_seconds):
print("Wake Up!")
playsound('audio.mp3') ## download the alarm sound from link
break
4. Rock paper scissors game
Create a game of rock-paper-scissors, where the player PKs with the computer. If a player wins, points are added to see who ends up with the most points.
Tip: Judge the player's choice first, then compare it to the computer's choice. The choice of computer is randomly selected from a selection list. If the player wins, add 1 point.
import random
choices = ["Rock", "Paper", "Scissors"]
computer = random.choice(choices)
player = False
cpu_score = 0
player_score = 0
while True:
player = input("Rock, Paper or Scissors?").capitalize()
# Determine the computer and the player's choice
if player == computer:
print("Tie!")
elif player == "Rock":
if computer == "Paper":
print("You lose!", computer, "covers", player)
cpu_score+=1
else:
print("You win!", player, "smashes", computer)
player_score+=1
elif player == "Paper":
if computer == "Scissors":
print("You lose!", computer, "cut", player)
cpu_score+=1
else:
print("You win!", player, "covers", computer)
player_score+=1
elif player == "Scissors":
if computer == "Rock":
print("You lose...", computer, "smashes", player)
cpu_score+=1
else:
print("You win!", player, "cut", computer)
player_score+=1
elif player=='E':
print("Final Scores:")
print(f"CPU:{cpu_score}")
print(f"Plaer:{player_score}")
break
else:
print("That's not a valid play. Check your spelling!")
computer = random.choice(choices)
5. Reminder gadgets
Use a reminder widget in Python to make reminder notifications on the desktop at a set time.
Tip: The Time module can be used to track reminder time, and the toastnotifier library can be used to display desktop notifications.
Installation: win10toast
from win10toast import ToastNotifier
import time
toaster = ToastNotifier()
try:
print("Title of reminder")
header = input()
print("Message of reminder")
text = input()
print("In how many minutes?")
time_min = input()
time_min=float(time_min)
except:
header = input("Title of reminder\n")
text = input("Message of remindar\n")
time_min=float(input("In how many minutes?\n"))
time_min = time_min * 60
print("Setting up reminder..")
time.sleep(2)
print("all set!")
time.sleep(time_min)
toaster.show_toast(f"{header}",
f"{text}",
duration=10,
threaded=True)
while toaster.notification_active(): time.sleep(0.005)
Epilogue
Today's sharing is a little difficult (for novices), if you are still a pure Python novice, I suggest adding my WeChat first
img
WeChat scan
Get free python introductory courses or materials