Question

Write program and programmer information as comments at the top of the script. Create a text...

  1. Write program and programmer information as comments at the top of the script.

  2. Create a text file called words.txt and include at least 20 English dictionary-based words in your folder.

  3. Program must read the list of words from the file into list data structure.

  4. Program chooses a random word from the list and starts asking player to guess the word one character at a time until player wins or runs out of predefined no. of tries.

  5. Game continues until the player wants to quit. Needs to be done in Python

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

CODE:

######## Program to guess a word from the file ##########
### Program by - Anubhav Singh #######

#library to randomly generate random numbers
import random

#input of file name
file = input("Enter the filename: ")

#opening file
f=open(file, "r")

#reading file data
contents =f.read()

#getting words
words = contents.split()

#closing the file
f.close()

#input of maximum attempts
tries = int(input("Enter the number of maximum tries for each words: "))

quit = "n"

#iterate unless, user quit
while quit == "n":
  
#getting random number in the range of total number of words in the file
i = random.randrange(0, len(words), 1)
word = words[i]
print("Word is choosen randomly ")
  
#iterating each character of word
for i in range(len(word)):
  
#input of guessed character
ch = input("Enter the "+str(i+1)+"th character: ")
  
#iterating for character input, unless user enters correct character or till maximum attempts
j = 0
while(ch!=str(word[i]) and j<tries):
ch = input("Incorrect character, try again: ")
j = j+1
  
if ch==str(word[i]):
print("You guessed it right.")
else:
print("It was ",ch)
print("Now, Guess the next character: ")
  
quit=input("Do you want to quit(y/n)")
      
SCREENSHOT:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Write program and programmer information as comments at the top of the script. Create a text...
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
  • Write a program IN PYTHON that checks the spelling of all words in a file. It...

    Write a program IN PYTHON that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list available below, called words.txt. The program should print out all words that it cannot find in the word list. Requirements Your program should implement the follow functions: main() The main function should prompt the user for a path to the dictionary file and a...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • (Python 3) Write a program that reads the contents of a text file. The program should...

    (Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...

  • Please complete the following: Write a Python script to do the following: 1. Ask the use...

    Please complete the following: Write a Python script to do the following: 1. Ask the use to enter several sentences, one at a time in a loop). To end the sentence entry, the user enters a blank (empty) sentence. 2. Extract each word from each sentence and put it in a list. This will require at least one loop to go through each sentence in the list. It is up to you how you want to get the words in...

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is...

    Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is a system that encodes a word into a letter followed by three numbers that roughly describe how the word sounds. Therefore, similar sounding words have the same four-character code. Use the following set of (slightly modified #4) rules to create a translator from English words to Soundex Code: Retain the first letter of the word. For letters 2 …n, delete any/all occurrences of the...

  • Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that...

    Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that uses iteration to guess a number from 1 to 10. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) a screenshot of the output, and 3) the Python program. Instructions Write pseudocode for a Python program that uses iteration to guess a number from...

  • C++ programming Submit assignment to Blackboard by the midnight on the due date listed above. (Verify...

    C++ programming Submit assignment to Blackboard by the midnight on the due date listed above. (Verify if your submission is completed.) The only people you are to discuss this project with are myself and the CS Department tutor. Duplicate code, if discovered, will result in a 0 grade. Your source file(s) should follow the Computer Science Coding Standards (available at the Computer Science Homepage) including proper indenting and spacing 1 Overview program, you will play a game of hangman. In...

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