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 \|/ | / \
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.
Answer :
Step by step
Solved in 2 steps with 5 images