Question

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 Py

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import random

ls=[]

#creating a list with all 26 letters
for i in range(65,91):
    ls.append(chr(i))

x=int(input("Enter the number of letters: "))

word=[]


#creating the word with blanks
for i in range(x):
    word.append('_')

print("Let's start guessing.")


#printing the word with blanks
for i in word:
    print(i,end=" ")
    
print("\n")
    
guess=[] #store the values already guessed by system

tries=0

#infinite loop for the game. Loop ends when user wins or number of turns are over.
while True:
    
    
    #get random guess from the system that was not already choosen in previous round
    while True:
        x=random.choice(ls) 
        
        if x not in guess:
            break
        
    guess.append(x)
    
    print("The computer guessed: ",x) #print the guess
    
    ch=input("Is the computer correct? (enter Y or y if yes): ") #heck if letter in the word
    
    if ch=='y' or ch=='Y':
        
        inp=input("Enter indexes where the letter is entered.") #get the indices where the letters are present
        
        places=inp.split(" ")
        
        for i in places:
            word[int(i)-1]=x #assign the letters in the word
            
    else:
        print("Number of Tries left = ",5-tries)
        tries=tries+1
        
    #print the word guess progress
    for i in word:
        print(i,end=" ")
    
    print("\n")
    
    #checks if system lost
    if tries==6:
        print("Sorry you used all your tries.")
        break
    
    #checks if system won
    if '_' not in word:
        print("You have won!!!")
        break
    
    

Output:

main.py JC++ input are. Enter the number of letters: 5 Lets start guessing. The computer guessed: Q Is the computer correct?

c/c++ input hare. Enter indexes where the letter is entered.4 QOZ The computer guessed: F Is the computer correct? (enter y o

main.py ++ input e. Enter the number of letters: 3 Lets start guessing. The computer guessed: A Is the computer correct? (en

Add a comment
Know the answer?
Add Answer to:
Code In Python Well Document Code Every Line Please * You cannot use any external Python...
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 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...

  • PYTHON CODE DOCUMENT EVERY LINE * You cannot use any external Python libraries. You can, of...

    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 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 is the same as...

  • 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...

  • 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...

  • 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...

  • 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...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • 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...

  • 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...

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