Python Guess the Word Game 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 &lt; limit:
    letter_guess = input('Guess a letter: ')

    if letter_guess in word:
        print('yes!')
        store_letter += letter_guess
        count += 1

    if letter_guess not in word:
        print('no!')
        count += 1

    if count == 2:
        print('\n')
        clue_request = input('Would you like a clue?')
        if clue_request == 'y':
            print('\n')
            print('CLUE: The first and last letter of the word is: ', clue)
        if clue_request == 'n':
            print('You\'re very brave!')

print('\n')
print('Now its time to guess. You have guessed',len(store_letter),'letters correctly.')
print('These letters are: ', store_letter)

word_guess = input('Guess the whole word: ')
while word_guess:
    if word_guess.lower() == correct:
        print('Congrats!')
        break

    elif word_guess.lower() != correct:
        print('Unlucky! The answer was,', word)
        break

print('\n')
input('Press Enter to leave the program')
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.



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. letter_guess.



while count &lt; limit:


Here you would use a for loop (for guess_count in range(limit)) like you suspected.



    letter_guess = input('Guess a letter: ')


I recommend you add some checking here to see if the letter is actually valid.



    if letter_guess in word:
        ...

    if letter_guess not in word:


If it was in the word previously, it still is. No need to re-check, you can just use else



            print('\n')


you can just use an empty print() to print a new line



        if clue_request == 'y':
            ...

        if clue_request == 'n':
            ...


what happens here if clue_request is neither 'y' nor 'n'? 



while word_guess:


what is the purpose of this while loop? All cases hit break



    if word_guess.lower() == correct:
        ...

    elif word_guess.lower() != correct:
        ...


You can just use else here again

Full program:

"""
Word Guess Game

by Coal_
"""
import random

WORDS = ('apple', 'oracle', 'amazon', 'microsoft')
correct_word = random.choice(WORDS)
clue = correct_word[0] + correct_word[-1]

store_letter = ''
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()

for guess_count in range(limit):
    while True:
        letter_guess = input('Guess a letter: ')

        if len(letter_guess) == 1:
            break
        else:
            print("Oops! Guess a letter!")

    if letter_guess in correct_word:
        print('yes!')
        store_letter += letter_guess
    else:
        print('no!')

    if guess_count == 2:
        print()
        clue_request = input('Would you like a clue?')
        if clue_request.lower().startswith('y'):
            print()
            print('CLUE: The first and last letter of the word is: ', clue)
        else:
            print('You\'re very brave!')

print()
print('Now its time to guess. You have guessed', len(store_letter), 'letters correctly.')
print('These letters are: ', store_letter)

word_guess = input('Guess the whole word: ')
if word_guess.lower() == correct_word:
    print('Congrats!')
else:
    print('Unlucky! The answer was,', correct_word)

print()
input('Press Enter to leave the program')