Question

In: Computer Science

Using pseudocode design a number guessing game program. The program should generate a random number and...

Using pseudocode design a number guessing game program. The program should generate a random number and then ask the user to guess the number. Each time the user enters his or her guess, the program should indicate it was too high or too low. The game is over when the user correctly guesses the number. When the game ends, the program should display the number of guesses that the user made.

Solutions

Expert Solution

Answer: Hello! Kindly find your solution here. If you have any queries, feel free to ask me. Thanks.

Python program-

import random
guessesTaken = 0
print('Hello! What is your name?')
myName = input()
number = random.randint(1, 20)
print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')

while guessesTaken < 6:

print('Take a guess.') # There are four spaces in front of print.

guess = input()

guess = int(guess)

guessesTaken = guessesTaken + 1

if guess < int(number):

print('Your guess is too low.') # There are eight spaces in front of print.

if guess > int(number):

print('Your guess is too high.')

if guess == number:

break

if guess == number:
guessesTaken = str(guessesTaken)
print('Good job')


if guess != number:
number = str(number)
  
  
print('Nope. The number of guesses taken:',guessesTaken)

Pseudocode-


function main()
guessesTaken = 0
output "Hello! What is your name?"
   input myname

Set number = random.randint(1, 20)

output"Well,myName, I am thinking of a number between 1 and 20."
while guessesTaken < 6

output "Take a guess."

   input guess

Set guessesTaken = guessesTaken + 1

if guess < number then

output"Your guess is too low."
   else
       if guess > number then

output"Your guess is too high."

   if guess == number then

Set guessesTaken = guessesTaken

output"Good job,correct guess"
       End program
  
if guess != number then
   Set number = number
output"Nope. The number of guesses" + guessesTaken

Output-

llo! hat is your ? jah 1. joke, I thinking of aber between 1 and 20. To geas is too lou, 12 You guess is too lon. Take a guess. 19 Your guess is too love. take a gaeas. Lour guess is too low. Take a guess. Your guess is too low. Take a guess. 18 Your guess is too low. ope. The number of guesses taken: 6


Related Solutions

Write a Java program that implements the Number Guessing Game: 1. First generate a random number...
Write a Java program that implements the Number Guessing Game: 1. First generate a random number (int) between 0 and 100, call it N 2. Read user input (a guess) 3. check the number, if it's smaller than N, output "The number is larger than that" 4. If the input is larger than N, output "The number is smaller than that" 5. If the input is equal to N, output " You got it!", and exit 6. Repeat until the...
Part (a) Write a number guessing game using System.Collections.Generic.Dictionary. Generate 10 distinct random numbers in the...
Part (a) Write a number guessing game using System.Collections.Generic.Dictionary. Generate 10 distinct random numbers in the range of 1 to 20. Each random number is associated with a prize money (from 1 to 10000). Use a Dictionary to store the mapping between the random number and the prize money. Ask user for two distinct numbers, a and b, both from 1 to 20; if a and b are not distinct, or out of range, quit the program Lookup the prize...
JAVA Write a number guessing game that will generate a random number between 1and 20 and...
JAVA Write a number guessing game that will generate a random number between 1and 20 and ask the user to guess that number. The application should start by telling the user what the app does. You should then create the random number and prompt the user to guess it. You need to limit the number of times that the user can guess to 10 times. If the user guesses the number, display some message that tell them that they did...
Random Number Guessing Game Write a program in C++ that generates a random number between 1...
Random Number Guessing Game Write a program in C++ that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high. Try again.” If the user’s guess is lower than the random number, the program should display “Too low. Try again.” The program should use a loop that repeats until the user correctly guesses the random number....
Random Number Guessing Game C++. Write a program that generates a random number between 5 and...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number in the range of 1 through 20, and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." If the user guesses the number, the application should congratulate the...
Program Created Last Week: #Program plays a guessing the number game with the user. #Importing random...
Program Created Last Week: #Program plays a guessing the number game with the user. #Importing random number with min number being 1 and max being 10 import random min_number = 1 max_number = 10 rand = random.randint(min_number, max_number) #Prints the header, welcoming the user print("Welcome to the Guess My Number Program!") while (True): #While loop, comparing the users guessed number with the random number. #If it matches, it will say you guessed it. guess = eval(input("Please try to guess my...
guessing game in Java. It will have a guess input used for guessing the random number...
guessing game in Java. It will have a guess input used for guessing the random number that is generated from 1 - 100. When the user makes a guess it will tell them if the number is lower or higher than the guess. There is also a choice to give up which then reveals the correct number. The last choice will be new game which resets the random number. Last, the program should keep counts of tries. When the user...
Part1. Create a number guessing game in Python. Randomly generate a number from 1 to 10....
Part1. Create a number guessing game in Python. Randomly generate a number from 1 to 10. Have the user guess the number. If it is too high, tell the user to guess lower - it it is too low, tell the user to guess higher. Continue until she guesses the correct number. - Part 2. Allow the user to play a new game after they have guessed correctly.   Part 3. Ask for a different name and keep track of how...
C++ The program implements the Number Guessing Game. However, in that program, the user is given...
C++ The program implements the Number Guessing Game. However, in that program, the user is given as many tries as needed to guess the correct number. Rewrite the program so that the user has no more than five tries to guess the correct number. Your program should print an appropriate message, such as “You win!” or “You lose!”.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT