Jul-10-2020, 04:58 PM
Keep at it you're doing good.
I modified your code a little to get it to work.
As GOTO10 suggest, there are better ways.
Keep up the good work.
I modified your code a little to get it to work.
As GOTO10 suggest, there are better ways.
Keep up the good work.
#! /usr/bin/env python3 import random letters = [] for num in range (97,123): letters.append (chr(num)) score = 0 rlist = random.sample(letters, 10) print(rlist) myword = [] while True: try: word = input('Enter a word: ') for ch in word: if ch in rlist: myword.append(ch) else: pass newword = ''.join(myword) myword = [] # Reset so it does not carryover if newword and len(newword) >= 3: score += 1 print(f'Your word is {newword} and your score is {score}') # Print results if match newword = [] #R eset else: print('Nah, try again') newword = [] # Reset except ValueError as error: print(error)
Output:['i', 'v', 'y', 'k', 'n', 'e', 'p', 'z', 'u', 'b']
Enter a word: puppy
Your word is puppy and your score is 1
Enter a word: ralph
Nah, try again
Enter a word: pop
Nah, try again
Enter a word: puke
Your word is puke and your score is 2
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