Back to articles
Creating a Guessing Game with Python
How-ToTools

Creating a Guessing Game with Python

via Dev.to BeginnersGuy Friley

Hello World! I decided that I would try putting my learning journey out there by creating a Github Repository and focusing on building and iterating over a Guessing Game developed with Python . The reason for doing this is to reinforce my Python learning journey, and to starting building things (however small) instead of getting stuck in Tutorial Hell. One thing I couldn't grasp, is how to capture errors, such as ValueError. Today, I did some reading, and decided to implement it into my simple game using Try-Except and ValueError as e. I did this so I could output the error in a print() statement. Generate Random Number for Number to Guess: # Generates a number from 1 - 10 inclusive my_number = random . randint ( 1 , 10 ) This generates a number from 1 to 10 with 1 and 10 being inclusive . Set Number of Guesses User has to guess the number: # Set variable num_guesses to 3 num_guesses = 3 Currently , this is hard - coded to 3 guesses , but later I will try and make this a user - editabl

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
6 views

Related Articles