# Find out how i can improve my Hangman coding on jupyter notebook

## Question:

enter image description herei want to find out how

1. i can take in user’s inputs on the number of times user wishes to run/play, and execute accordingly. and also how can i provide user with an option on the game/run mode

2. allow the user to choose the complexity level of a game?

3. include a scoreboard that shows the top 5 players/scores.

[enter image description here](https://i.stack.enter image description hereimgur.com/CcJOM.png)

``````from IPython.display import clear_output

import random
NUMBER_OF_PICKS = 3
MINIMUM_SELECTION = 1
MAXIMUM_SELECTION = 36

#Input for the word by game master
print("Hi " + user + " good luck ")
no_of_time = input("How many times do you want to play: ")

clear_output()
win = False

#defining function

clear_output()
if len(guess)==1:
print("Correct, ",guess," is a right letter")
return True
else:
print("Incorrect, ",guess, " is a not a correct letter. That was your chance number ",guess_no)
return False
else:
print("Enter only one letter")

#Storing the number of characters in different variable

#initializing number of allowable guesses
guess_no = 1
while guess_no<5:
clear_output

#Player input for guess letter

#Calling a sub function to check if correct letter was guessed

#Conditional: if incorrect letter
if guess_check == False:
guess_no +=1
#Conditional: if correct letter
elif guess_check == True:
num = [i for i, x in enumerate(answer_word) if x == guess_letter] #https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list
for all in num:

#Conditional: if no remaining unknown letter then win screen
win = True
break

if win:
print("You won!")
else:
print("You lost!")
``````

To install `random_words` package in jupyter notebook.

run this command in code shell.
`!pip install random_word`

import package. `from random_word import RandomWords`

generate.

``````r = RandomWords()
print(r.get_random_word())
``````

Code snippet:

``````import random
from random_word import RandomWords

# Input for the word by game master
print("Hi " + user + " good luck ")

while True:
try:
no_of_time = int(input("How many times do you want to play: "))
played_time = no_of_time
break
except ValueError:
print("Please enter a number. specify in number how many time you want to play.")

r=RandomWords()
scorecard = 0

# defining function
if len(guess) == 1:
print("Correct, ", guess, " is a right letter")
return True
else:
print("Incorrect, ", guess, " is a not a correct letter. That was your chance number ", guess_no)
return False
else:
print("Enter only one letter")

while no_of_time:

while True:
try:
difficulty_level = int(input(
"Enter the difficulty you want to play: press [1] for easy, press [2] for medium, press [3] for hard, press [4] for manually word"))
if difficulty_level in [1, 2, 3, 4]:
break
else:
print("Enter number 1 or 2 or 3 or 4 not other than that!!")
continue
except ValueError:

if difficulty_level == 1:
elif difficulty_level == 2:
elif difficulty_level == 3:
else:
answer_word=input("Enter manually what word you wanted to set..!")

win = False
# Storing the number of characters in different variable

# initializing number of allowable guesses
guess_no = 1
while guess_no <= 5:  # User chances given 5

# Player input for guess letter
guess_letter = str.lower(input('Enter your guess letter: '))

# Calling a sub function to check if correct letter was guessed

# Conditional: if incorrect letter
if guess_check == False:
guess_no += 1
# Conditional: if correct letter
elif guess_check == True:
num = [i for i, x in enumerate(answer_word) if
x == guess_letter]  # https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list
for all in num:

# Conditional: if no remaining unknown letter then win screen
win = True
break

if win:
print("You won!")
scorecard += 1
else:
print("You lost!")

no_of_time -= 1

print("You played " + str(played_time) + ":")
print("Won: " + str(scorecard) + " Guessed correctly!!")
print("Lose: " + str(played_time - scorecard) + "not Guessed correctly!!")
``````

don’t know why specific length is not working in `random_word` hence included `while` statement.. this code snippet is working you can go through this..!

Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.