And one more
#! /usr/bin/env python3 import random import string from subprocess import call import os # Start score at zero score = 0 # Create a empty list myword = [] # Function to clear screen of cluttered text def clear(): _ = call('clear' if os.name == 'posix' else 'cls') clear() # Start the while loop while True: # Get 10 letters from the alphabet letters = random.sample(string.ascii_lowercase, 10) # Print letters to choose from print(f'\n{letters}') try: print('\nType q and press enter to exit.\n') # Ask for a word word = input('Enter a word: ').lower() # A way to exit the game if word == 'q': break # Compare our word with the letters list and creat a list of matched letters [myword.append(ch) for ch in word if ch in letters] # Join the letters in list to make word myword = ''.join(myword) # Check to see if myword has letters and there is at least 3 if myword and len(myword) >= 3: # Increase score by 1 score += 1 # Clear screen and print message clear() print(f'\nYour word is {myword}.') print(f'Boom! Your score is now {score}.') # Reset myword to empty list myword = [] else: # Clear screen and print message and continue clear() print(f'\nSorry, please try again.') # Reset myword to empty list and continue myword = [] continue except ValueError as error: print(error)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags