Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word Game
#3
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.

#! /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


Reply


Messages In This Thread
Word Game - by paulmerton4pope - Jul-10-2020, 12:44 PM
RE: Word Game - by GOTO10 - Jul-10-2020, 04:51 PM
RE: Word Game - by menator01 - Jul-10-2020, 04:58 PM
RE: Word Game - by menator01 - Jul-10-2020, 07:10 PM
RE: Word Game - by paulmerton4pope - Jul-11-2020, 02:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the word game help jackthechampion 3 2,958 Sep-06-2023, 06:51 AM
Last Post: Pedroski55
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,455 Aug-12-2021, 04:25 PM
Last Post: palladium
  Python Speech recognition, word by word AceScottie 6 15,858 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 4,719 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  difference between word: and word[:] in for loop zowhair 2 3,622 Mar-03-2018, 07:24 AM
Last Post: zowhair

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020