GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • Why Practice Python?
  • Why Chilis?
  • Resources for learners
  • Exercises
  • Blog
  • About

This view

  • Original page
  • New address

GeezerVison is showing www.practicepython.org — 31 Guess Letters

Practice Python

  • follow us in feedly
  • Atom feed XML
Follow @practice_python

Beginner Python exercises

  • Home
  • Why Practice Python?
  • Why Chilis?
  • Resources for learners
  • Exercises
  • Blog
  • About

02 January 2017

Guess Letters

Exercise 31 (and Solution)

This exercise is Part 2 of 3 of the Hangman exercise series. The other exercises are: Part 1 and Part 3.

Let’s continue building Hangman. In the game of Hangman, a clue word is given by the program that the player has to guess, letter by letter. The player guesses one letter at a time until the entire word has been guessed. (In the actual game, the player can only guess 6 letters incorrectly before losing).

Let’s say the word the player has to guess is “EVAPORATE”. For this exercise, write the logic that asks a player to guess a letter and displays letters in the clue word that were guessed correctly. For now, let the player guess an infinite number of times until they get the entire word. As a bonus, keep track of the letters the player guessed and display a different message if the player tries to guess that letter again. Remember to stop the game when all the letters have been guessed correctly! Don’t worry about choosing a word randomly or keeping track of the number of guesses the player has remaining - we will deal with those in a future exercise.

An example interaction can look like this:

>>> Welcome to Hangman!
_ _ _ _ _ _ _ _ _
>>> Guess your letter: S
Incorrect!
>>> Guess your letter: E
E _ _ _ _ _ _ _ E
...

And so on, until the player gets the word.

Happy coding!

Enjoying Practice Python?

Buy me a coffee

Share the fun!

« Previous exercise Next exercise »

Explore Yubico
Explore Yubico
comments powered by Disqus
Copyright Michele Pratusevich, 2014-2022.
Advertising disclosure
You are visitor 01402860 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.