Password The Game Word List
When I was putting together this site of games, I discovered that my printable word lists became very popular. I had word lists for pictionary, charades, and other.
Can the following code be simplified/ improved? (NOTE: I am yet to learn OOP/ def functions). I have not used OOP and def functions on purpose, as I am yet to learn this aspect of Python. I have listed some things I would like to improve on below. • Could/ Should I implement for loops? • Is the structure of the code of a good standard?
• How can I simplify the code (using less loops/ less code in general)? # Python 3.4.3 // MacOS (Latest) import random WORD = ('apple', 'oracle', 'amazon', 'microsoft') word = random.choice(WORD) correct = word clue = word[0] + word[(len(word)-1):(len(word))] letter_guess = ' word_guess = ' store_letter = ' count = 0 limit = 5 print('Welcome to 'Guess the Word Game!' ') print('You have 5 attempts at guessing letters in a word') print('Let 's begin!' ) print(' n') while count. In this case it's totally fine to not define any functions or classes.
It does not always make sense to use those things just because you can. In this case for loops do indeed make sense. The structure is pretty straight forward, but you should revise what if, else and elif do. Correct = word Not quite sure what you are doing here by having two variables with the same content.
Password The Game Rules
Clue = word[0] + word[(len(word)-1):(len(word))] You can use negative indexes to count from the end of the sequence: That would make this line: clue = word[0] + word[-1] letter_guess = ' word_guess = ' store_letter = ' count = 0 limit = 5 you could use more descriptive names like: guess_limit, guess_count etc. Some of these variables don't need to be set here yet, e.g.