Write program and programmer information as comments at the top of the script.
Create a text file called words.txt and include at least 20 English dictionary-based words in your folder.
Program must read the list of words from the file into list data structure.
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.
Game continues until the player wants to quit. Needs to be done in Python
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:
Write program and programmer information as comments at the top of the script. Create a text...
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...
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: 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 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. (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 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 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 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...
Exercise 6: Program exercise for 2D List Write a complete Python program including minimal comments (file name, your name, and problem description) that solves the following problem with the main function: Problem Specification: The following code reads values from the file object infile and stores them in the 2d list table2: (It assumes that each line contains values of elements in each row and the values are whitespace separated.) table2 = [] for line in infile: row=line.split() intRow = []...
python question
Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to play each game. Call the file containing your program fun games.py. Your program should include the following functions: • function guess The Number which implements the number guessing game. This game is played against the computer and outputs the result of the game (win/lose) as well as number of guesses the user made to during the...