Question

In: Computer Science

Exercise: What does the following program guess.py do? Write your answer in the file explanation.txt. guess.py...

Exercise: What does the following program guess.py do? Write your answer in the file explanation.txt.

guess.py program

import random

number = random.randint(1, 25)

number_of_guesses = 0

while number_of_guesses < 5:

print('Guess a number between 1 and 25:')

guess = input()

guess = int(guess)

number_of_guesses += 1 if guess == number: break

Solutions

Expert Solution

Explanation:

The progam is a guessing game.

The user has to guess a number within five tries.

If the user, guesses within five tries then the program terminates.

If not, it will run until the user has tried five times.

Program imports random module to call the randint() function.

It generate a random integer between 1 and 25 by calling randint() function.

A variable is used as a counter to remember the number of guesses guessed by the user.

A while loop is used to iterate the guessing process.

Program:

#importing random module for randint() function
import random

#Generating a random number between 1 and 25 using randint() function
number = random.randint(1, 25)

#variable to count number of guesses
number_of_guesses = 0

#Loop for five tries.
while number_of_guesses < 5:
  
print('Guess a number between 1 and 25:')
  
#input from user
guess = input()
  
#typecasting user input to int
guess = int(guess)
  
#incrementing the number of guesses
number_of_guesses += 1
  
#If the guess is correct exit the loop
if guess == number:
break

Sample Run 1:

Sample Run 2:

For Indentation:


Related Solutions

Write a C++ Program that does the following: As you can see, there is a file...
Write a C++ Program that does the following: As you can see, there is a file named "invoice1_test1.txt". You are to use this file as your input file for your program. Do the following: 1. Sort the file by last name using an array. You can use any of the sorting algorithms we have previously used in class. You may use the string data type to store text data. 2. Compute the following: a. The total balance due using the...
Write a C++ program that does the following: Read and input file containing the following PersonAName,...
Write a C++ program that does the following: Read and input file containing the following PersonAName, PersonBName, XA,YA, XB, YB where the coordinates of PersonA in a 100 by 100 room is XA, YA and the coordinates of PersonB is XB, YB. Use square root function in cmath sqrt() to calculate the shortest distance between two points. A file will be uploaded in this assignment that will list coordinates of two people. The program should use a function call that...
Write a python program that does the following: Prompt for a file name of text words....
Write a python program that does the following: Prompt for a file name of text words. Words can be on many lines with multiple words per line. Read the file and convert the words to a list. Call a function you created called list_to_once_words(), that takes a list as an argument and returns a list that contains only words that occurred once in the file. Print the results of the function with an appropriate description. Think about everything you must...
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
Write a java program: Write a program that creates a text file. Write to the file...
Write a java program: Write a program that creates a text file. Write to the file three lines each line having a person's name. In the same program Append to the file one line of  'Kean University'.  In the same program then Read the file and print the four lines without lines between.
Write a C++ program that creates a file called Readings.txt. Inside the file, your program must...
Write a C++ program that creates a file called Readings.txt. Inside the file, your program must create a list. The list is composed of integer double pairs. There is one pair per line. The integers are in sequence (0, 1, 2, 3, ...) beginning with zero and ending with some random value between 512 and 1024. The doubles should be random values between 50.000 and 90.000. The doubles only have 3 decimal places. The file should look like this (of...
Write a complete Java program that does the following: Open an input file named data.txt that...
Write a complete Java program that does the following: Open an input file named data.txt that consists of a series of unknown number of integers. If data.txt does not exist, give an appropriate error message and terminate the program. Define a constant MAX of value 100 and create an array of size MAX to hold items from the input file. Make sure your program will not generate ArrayIndexOutOfBounds exception. Open an output file named result.txt and write the array elements...
Write a c++ program that does the following, read temperatures from a file name temp.txt into...
Write a c++ program that does the following, read temperatures from a file name temp.txt into an array, and after reading all the temperatures, output the following information: the average temperature, the minimum temperature, and the total number of temperatures read. Thank you!
(PYTHON) Write a program that does the following: reads each line from a txt file and...
(PYTHON) Write a program that does the following: reads each line from a txt file and convert it to lowercase counts the number of instances of: the characters 'a', 'e','i','o' and 'u' in the file creates a new file of file type .vowel_profile print outs lines in the file indicating the frequencies of each of these vowels Example input/output files: paragraph_from_wikipedia.txt (sample input) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.txt paragraph_from_wikipedia.vowel_profile (sample output) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.vowel_profile Please help!
1. Write a program that does the following. Write in Assembly Language program Loads your student...
1. Write a program that does the following. Write in Assembly Language program Loads your student ID number into memory starting at location 0x2000 0100 a. DO NOT do any conversion on your ID number. If my ID number is 123456789, I should be able to read your ID in memory as 123456789 2. Loads the first six characters of your name, in ASSIC, in to memory right after your student ID. Total of 6 bytes. a. This means that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT