1. Write a pyrhon program that prints out a classic hangman stick figure. The program should ask the user to enter a number from 1-6 and the corresponding hangman should be printed. The value the user inputs corresponds to the number of incorrect guesses in a real hangman game and so the completeness of the hangman will correspond to the number of ‘incorrect guesses’ inputted by the user (e.g., if the user enters 1, then only the head of the hangman will be printed; full example below). Example: Enter a number from 1-6: 1 O Enter a number from 1-6: 2 O | Enter a number from 1-6: 3 O \| | Enter a number from 1-6: 4 O \|/ | Enter a number from 1-6: 5 O \|/ | / Enter a number from 1-6: 6 O \|/ | / \

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 14E
icon
Related questions
Question

1. Write a pyrhon program that prints out a classic hangman stick figure. The program should ask the user to enter a number from 1-6 and the corresponding hangman should be printed. The value the user inputs corresponds to the number of incorrect guesses in a real hangman game and so the completeness of the hangman will correspond to the number of ‘incorrect guesses’ inputted by the user (e.g., if the user enters 1, then only the head of the hangman will be printed; full example below).

Example:
Enter a number from 1-6: 1
O

Enter a number from 1-6: 2
O
|
Enter a number from 1-6: 3
O
\|
|
Enter a number from 1-6: 4
O
\|/
|
Enter a number from 1-6: 5
O
\|/
|
/
Enter a number from 1-6: 6
O
\|/
|
/ \

2. Modify your program from problem 1 so that the user input is checked to be a valid
single digit (1-6) before printing the corresponding hangman. If the input is not valid, then
instead of a hangman the following message should be printed “Invalid input: you must enter a
single number from 1-6.”

Example:
Enter a number from 1-6: 7
Invalid Input: you must enter a number from 1-6

Challenge: Instead of returning a generic error / invalid input message, try adding some
specificity. i.e., if the inputted string is not a number, then the returned message should specify
that the problem is that it is not a digit; if the inputted string is too long, then the returned
message should specify that the problem is that it is too long / not a single character.

Expert Solution
steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning