Question

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 Py

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

import random
print(".......making the computer select how many lives it wants between 1 to 10 lives\n")
lives = random.randint(1,10) #randomly chooses a number of life for the computer
print("Computer chose {} lives\n".format(lives))
print("Please think of a word.......\n")
while True: #to make sure whether the player has chosen a word
valid = input("\nHave you decided the word? (Y/N)/(y/n)")
if valid in ['Y','y']: #if the input is 'Y' then loop breaks
print("Great!")
break
else:
print("Hurry up!")
print(".........\nComputer will start guessing now!\n") #from jhere computer starts guessing
#we break the game in two parts... guessing vowels then guessing consonants
vowel_list = list("aeiou") #list of vowels
consonant_list = list("bcdfghjklmnpqrstvwxyz") #list of consonants
blanks = 0 #used to denote the no of spaces left blank
next_part = True #will be used to see if the guessing of consonant part is to be executed
while True: #infinite loop to be broken on certain conditions
if len(vowel_list) <= 0 or lives <= 0: #if the comouter has chosen everything from vowels or lives is 0 then exit loop with next_part = True
break
choose = random.choice(vowel_list) #randomly chooses a variable in vowel_list
vowel_list.remove(choose) #we remove that variable from the list so that it does not guess same thing
print("\nComputer chose-> ",choose) #printing what computer chose
valid = input("Is the letter '"+str(choose)+"' present in your guessed word? (y/n)") #taking your input if the letter is present in your word
if valid not in ['Y','y']: #if not present then deduct a life
print("\n(XXXXX) Oops! Computer lost a life!")
lives -= 1
else:
print("\nGreat! Computer guessed a letter right!")
word_now = input("Enter the current word with blanks..... (_) for blank: ") #enter the current state of the word with blanks
blanks = list(word_now).count('_') #counting the number of blanks
if blanks == 0 and lives > 0: #if no of blanks is 0 and lives > 0 then computer won!
next_part = False #since the word only had vowels there is no need of executing the consonant guessing part
print("\n\nCOMPUTER WON!\n")
break #exit loop (PROGRAM END)

while next_part: #from vowel part if the next_part is unchannged and next_part is true then infinite loop
if lives <= 0: #if lives get 0 then computer lost exit
print("\n\nCOMPUTER LOST!")
break
choose = random.choice(consonant_list) #randomly chooses a letter in consonant_list
consonant_list.remove(choose) #removes the letter from the list so that it doesn't repeat again
print("\nComputer chose-> ",choose) #printing computer's chosen word
valid = input("Is the letter '"+str(choose)+"' present in your guessed word? (y/n)") #asking if the letter is present in your word or not
if valid not in ['Y','y']: #if not present then deduct a life
print("\n(XXXXX) Oops! Computer lost a life!")
lives -= 1
else:
print("\nGreat! Computer guessed a letter right!")
word_now = input("Enter the current word with blanks..... (_) for blank: ") #enter the current state of the word with blanks
blanks = list(word_now).count('_') #if no of blanks is 0 and lives > 0 then computer won!
if blanks == 0 and lives > 0: #if no of blanks is 0 and lives > 0 then computer won!
print("\n\nCOMPUTER WON!\n")
break #exit loop (PROGRAM END)

[2]: import random print(.......making the computer select how many lives it wants between 1 to 10 lives\n) lives = random.break choose random.choice(vowel_list) #randomly chooses a variable in vowel_list vowel_list.remove(choose) #we remove that vprint InGreat: Computer guessed a letter right! word_now = input(Enter the current word with blanks....... for blank: ) #en

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

  • 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