Question
PYTHON CODE
DOCUMENT EVERY LINE

* You cannot use any external Python libraries. You can, of course, import the libraries that are included in the standard Py
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#Libraries that are include in standard python installation.
#string for generating the small and capital letters from A to Z and a to z.
import string
#Random to pick a letter randomly from the set of letters generated by string.
import random
#Function to guess the word.
def reversed_packman():
print("Think a word")
#Inputting the length of word.
number_of_letters = int(input("Enter number of letters in the word you think: "))
#Variable which stores the guessed word.
guessed_word = ''
#Checking if the user guess a valid word.
if(number_of_letters>=2):
#Used for output formatting(first letter and next letters) in loop.
letter_counter = 1
#Running a while loop till all the letters of the word are guessed.
while(number_of_letters>0):
#Variable which stores the random letter generated using string and random library.
random_letter = random.choice(string.ascii_letters)
#Checking if the computer is guessing the first letter.
if(letter_counter==1):
#inputting the result.
result = input("Is your word starts with letter '"+random_letter+"'. If true enter yes otherwise enter no: ")
#Doing necessary manipulation if the letter guessed correct.
if(result=='yes'):
#This ensures the next time else statement will run.
letter_counter += 1
#This ensures the loop runs or not next time.
number_of_letters -= 1
#Adding the guessed letter to guessed word.
guessed_word += random_letter
#Same as if.
else:
result = input("Is the next letter of your word is '" + random_letter + "'. If true enter yes otherwise enter no: ")
if(result=="yes"):
number_of_letters -= 1
guessed_word += random_letter
#Printing the correct word.
print("Correct word guessed by the computer is: \"" + guessed_word+"\"")
else:
print("Please think a correct word")

#Calling the function.
reversed_packman()

CODE SCREENSHOT:

#Libraries that are include in standard python installation. #string for generating the small and capital letters from A to Z

else: print(Please think a correct word) #Calling the function. reversed_packman ()

CODE OUTPUT:

no no no Think a word Enter number of letters in the word you think: 3 Is your word starts with letter f. If true enter yes

Add a comment
Know the answer?
Add Answer to:
PYTHON CODE DOCUMENT EVERY LINE * You cannot use any external Python libraries. You can, of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Code In Python Well Document Code Every Line Please * You cannot use any external Python...

    Code In Python Well Document Code Every Line Please * You cannot use any external Python libraries. You can, of course, import the libraries that are included in the standard Python installation though. * Your software must use selection (if, if/ else, etc.) and repetitive (for, while, etc) control structures and have programmer defined functions. * Make sure you understand the code you submit since you will be expected to answer questions about it. The way the program should work...

  • Code In Python Well Document Code Every Line Please * You cannot use any external Python...

    Code In Python Well Document Code Every Line Please * You cannot use any external Python libraries. You can, of course, import the libraries that are included in the standard Python installation though. * Your software must use selection (if, if/ else, etc.) and repetitive (for, while, etc) control structures and have programmer defined functions. * Make sure you understand the code you submit since you will be expected to answer questions about it. The way the program should work...

  • Code In Python Well Document Code Every Line Please 5 Stars * You cannot use any...

    Code In Python Well Document Code Every Line Please 5 Stars * You cannot use any external Python libraries. You can, of course, import the libraries that are included in the standard Python installation though. * Your software must use selection (if, if/ else, etc.) and repetitive (for, while, etc) control structures and have programmer defined functions. * Make sure you understand the code you submit since you will be expected to answer questions about it. The way the program...

  • javafx assisantance confused on where to start Problem Description: (Game: hangman) Write a JavaFX program that...

    javafx assisantance confused on where to start Problem Description: (Game: hangman) Write a JavaFX program that lets a user play the hangman game. The user guesses a word by entering one letter at a time, as shown in Figure followings. If the user misses seven times, a hanging man swings, as shown in Figures. Once a word is finished, the user can press the Enter key to continue to guess another word. Guess a word: ***** God Missed letters Guess...

  • C++ Hangman (game) In this project, you are required to implement a program that can play...

    C++ Hangman (game) In this project, you are required to implement a program that can play the hangman game with the user. The hangman game is described in https://en.wikipedia.org/wiki/Hangman_(game) . Your program should support the following functionality: - Randomly select a word from a dictionary -- this dictionary should be stored in an ASCII text file (the format is up to you). The program then provides the information about the number of letters in this word for the user to...

  • Python Problem Hello i am trying to finish this code it does not save guesses or...

    Python Problem Hello i am trying to finish this code it does not save guesses or count wrong guesses. When printing hman it needs to only show _ and letters together. For example if the word is amazing and guess=a it must print a_a_ _ _ _ not a_ _ _ _ and _a_ _ _ separately or with spaces. The guess has a maximum of 8 wrong guesses so for every wrong guess the game must count it if...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • PLEASE DO IN JAVA You can use any source for the dictionary or just a few...

    PLEASE DO IN JAVA You can use any source for the dictionary or just a few words are fine! description The purpose of this assignment is to practice with ArrayLists (and hopefully, you'll have some fun). As far as the user knows, play is exactly as it would be for a normal game of hangman, but behind the scenes, the computer cheats by delaying settling on a mystery word for as long as possible, which forces the user to use...

  • Overview In this exercise you are going to recreate the classic game of hangman. Your program...

    Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT