Skip to main content

User Friendly Function

So, here comes the last one and the user's function, here, in this function we will look into how user will be given hints to solve the puzzle and how the solving will go and how he/she won't be able to cheat!
 Let's jump directly into the code and see how that will happen:

CODE:

    def get_next_letter(remaining_letters):
    """Get the user-inputted next letters."""
    if len(remaining_letters) == 0:
        raise ValueError('There are no remaining letters')
    while True:
        next_letter = input('Choose the next letter: ').lower()
        if len(next_letter) != 1:
            print('{0} is not a single character'.format(next_letter))
        elif next_letter not in ascii_lowercase:
            print('{0} is not a letter'.format(next_letter))
        elif next_letter not in remaining_letters:
            print('{0} has been guessed before'.format(next_letter))
        else:
            remaining_letters.remove(next_letter)
            return next_letter

 Now, in this we can see that first we will take the user inputted letters and the user will use these letters to fill in these spaces. As soon as the user inputs correct letter all the spaces with that letters will be filled. Then, if user tries to cheat by inputting 2 letters in single go then, the message will be displayed that the inputted letter is not a single character and his one life will be taken away, if user enters special character then also it will display the message and the last if user has used one letter out of 26 alphabets then he cannot use that letter again! that's is helping right?:)
So, now there is only main function remaining, we'll look into that someday later! Till then have a good day!
                                                                                                                          - Shreepad Sapate(L-60)





















Comments

Post a Comment

Popular posts from this blog

Project Documentation

Course Project Title: HANGMAN GAME in Python Description: An interactive game of Hangman developed using python(an object programming language).The project consists of a number of functions used in the game by making use of inbuilt Python libraries.The game offers the user to choose number of attempts and also shows a graphical output. Link for project report: here Final Code File :  Python Code Topic 1: Hangman graphic function Presentor's info:  Name: Siddhesh Ramajgol Div: TY-L Roll no: 57 GR.no : 1710081 Video Link:   Hangman Graphic Function Topic 2: Get no.of attempts and word length Presentor's info:  Name:  Kartik Mehetre Div: TY-L Roll no: 47 GR.no :  1710382 Video Link:  No.of attempts and word length Topic 3: Get next letter and display words Presentor's info:  Name: Shreya Uttarwar Div: TY-L Roll no: 69 GR.no :  1710360 Video Link:  Get next letter and display ...

Journey towards Creating Hangman.

I love when people take a sophisticated tool and use it to play video games. Take Unity for example. I first saw my friends created a game in Unity, which was an Virtual reality game. My friends Vivek and Payas then inspired me to more efficiently waste time in creating something of my own like their VR game. Rather than jumping directly to a VR game so we thought to start something from the basics. So, the other day I had an immense amount of college work to do and decided it was the perfect time to make a hangman game.  So, What is hangman? In its purest form, hangman is a word game played between two people. One person selects a secret word, and the other tries to determine the word by guessing it letter-by-letter. The player with the secret writes a series of dashes, one representing each letter in the solution. Initially, no information is known about the target word, other than its length. The solver calls out letters, one-by-one. If a called letter appears in the solutio...

The output!

So here we arrive at the OUTPUT ! When you run the code in any Python IDE you will get results as follows: We are planning to put a video explaining each part of the source code in the next and final post for this blog. So, do visit again! Happy Learning!                                                             -Kartik Mehetre