How to implement Hangman Games with Python
Most people do not understand the knowledge points of this "Python how to achieve Hangman game" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Python how to achieve Hangman game" article.
Email address slicer
Goal: write a Python script that can get a user name and domain name from an email address
Tips: use @ as the delimiter to divide the address into 2 strings
2. Send mail automatically
Goal: make a script that automatically sends e-mail
The tips:email library can be used to send e-mail.
Import smtplib from email.message import EmailMessageemail = EmailMessage () # # Creating an object for EmailMessageemail ['from'] =' xyz name' # # Person who is sendingemail ['to'] =' xyz id' # # Whom we are sendingemail ['subject'] =' xyz subject' # # Subject of emailemail.set_content ("Xyz content of email") # # content of emailwith smtlib.SMTP (host='smtp.gmail.com' Port=587) as smtp: # # sending request to server smtp.ehlo () # server objectsmtp.starttls () # # used to send data between server and clientsmtp.login ("email_id", "Password") # # login id and password of gmailsmtp.send_message (email) # # Sending emailprint ("email send") # # Printing success message III
Goal: to make a script that can generate acronyms for a given sentence
Tips: the first word can be obtained by indexing and splitting and then combined
IV. Word adventure games
Goal: make an option that allows users to take interesting adventures by choosing different paths
5. Hangman games
Goal: make a command line Hangman game
Tips: create a list of password words and randomly select a word, each word is represented by an underscore "_", giving the user a chance to guess the word. If the guess is right, the word will be replaced with "_".
Import timeimport randomname = 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 Wordswords = ['python','programming','treasure','creative','medium' 'horror'] word = random.choice (words) guesses =' 'turns = 5while 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") the above is the content of this article on "how Python implements Hangman games" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.