Ad

Split Each Alphabet in a String

You can use this method to split words.

def split(word):
    # if word is "hello" returns ["h", "e", "l", "l", "o"]
    return [x for x in word]

Hello Everybody I would like your help to improve the code quality of this very old, simple and scrappy code I made when I started to code as a hobby.

import random


def code():
    print('Guess a number between 1 and 25')

    # secret number
    secret_number = random.randint(1, 25)

    guess_count = 0
    guess_limit = 5

    # mainloop
    while guess_count < guess_limit:
        try:
            guess = int(input('\nGuess: '))
            guess_count += 1

        except ValueError:
            print("\nInvalid Input!")
            continue

        if guess > secret_number:
            print('\nNo, too big.')
            guess_count += 1

        elif guess < secret_number:
            print('\nNo, too small.')
            guess_count += 1

        elif guess == secret_number:
            print('\nWow, you are a actully are a true mind reader!')
            print(f"The number was {secret_number} indeed! ")
            reply = input('\nDo you want to play guess again? (yes/no) - ')
            if reply == 'yes':
                code()
            else:
                exit()

        if guess_count == 5:
            print('\nSorry, you have failed:(')
            print(f'\nThe secret number was {secret_number}.')

            replay = input('\nDo you want to play Guess game again? (yes/no) - ')
            if replay == 'yes':
                code()
            elif replay == 'no':
                exit()
            else:
                print("I don't understand")


code()