Question

Draw a flowchart and pseudocode that describes the process of guessing a number between 1 and...

Draw a flowchart and pseudocode that describes the process of guessing a number between 1 and 100.

-Make a working version of this program in Python. ( need the correct code for program )

-After each guess, the player is told that the guess is too high or too low.

-The process continues until the player guesses the correct number.

Homework Answers

Answer #1

'''

Python version : 2.7

Python program to implement the guessing game

'''

import random

# generate a random number between [1,100]

num = random.randint(1,100)

attempts = 0

print("Welcome to the guessing game!")

# loop that continues till the user guesses the number

while True:

               # input of the guess

               guess = int(raw_input('Enter your guess : '))

               attempts += 1

               # check if guess is correct, break from the loop

               if guess == num:

                              break

               elif guess < num: # if guess < num, print 'Too low'

                              print('Too low')

               else: # if guess > num, print 'Too high'

                              print('Too high')

# print the number of attempts it took to guess the number                           

print('Congratulations!! You guessed the number in %d attempts '%(attempts))                      

                             

#end of program             

Code Screenshot:

Output:

// Pseudocode to guess the number
Declaration
   number guess, num;
   number attempts
  
Start

   num = generate a random number between 1 and 100 (inclusive) ;
  
   attempts = 0 ; // initialize attempts to 0
  
   Input guess; //input the guess value from user
  
   attempts = attempts + 1; // increment the attempts
  
   // loop that continues till the user has guessed the number
   while guess != num
   do
       // check if guess is low or high
       if guess > num then
           print('Too high');
       else
           print('Too low');
       end if
      
       Input guess; //input the guess value from user
      
       attempts += 1;// increment the attempts
   end while
  
   // output the number of attempts it took the user to guess the number
   print("Congratulations!! You guessed the number in ",attempts," attempts ")  
End  

Flowchart:

Know the answer?
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
Similar Questions
Please make a Python program where the computer chooses a number and the player guesses the...
Please make a Python program where the computer chooses a number and the player guesses the number. And at the end, please report the number of attempts. You need an input, a random number, if statement, and a while loop. Please reference the pre-lab document in the Blackboard. Please prepare a Word document that has the Python code and the screen shot of your output. Here is a sample of what the output screen should look like. What is your...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program that comes up with a random number and the player has to guess it. The program output can be like this: I am thinking of a number between 1 and 20. Take a guess. 10 Your guess is too low. Take a guess. 15 Your guess is too low. Take a guess. 17 Your guess is too high. Take a guess. 16 Good job!...
[15 marks] Draw the flowchart of the following programming problem: You can draw the flowchart using...
[15 marks] Draw the flowchart of the following programming problem: You can draw the flowchart using a drawing tool, or draw the flowchart on a piece of paper, take a picture, insert it here or save it in the submission folder The program randomly generates an integer between 0 and 100, inclusive. The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each user input, the program tells the user whether...
Goal: Write a simple number guessing game in java. The game picks a number between bounds...
Goal: Write a simple number guessing game in java. The game picks a number between bounds input by the user, then user has to guess the number. The game will tell you if your guess is too high or too low. When you guess it, the game will tell you how many guesses it took Run multiple games and print statistics (# games, # guesses, avg) when all done. Sample Run: G U E S S I N G G...
Write a c++ program that has the user guess a number between 1 and 100, you...
Write a c++ program that has the user guess a number between 1 and 100, you program should output correct guess if the user guess the right number, too high if they guess a number higher, too low if the guess a number lower and handle invalid input
Here is my problem: In Swift I, you used your knowledge at the time to create...
Here is my problem: In Swift I, you used your knowledge at the time to create a High / Low Guessing Game.   This week, you will update (or create a new version of) the game using the knowledge you've now attained. You will be creating a High/Low guessing game as outlined below: In this game: Your app will think of a random number between 0 and 999, and you (the player) will have to guess the number. You can use...
Game to guess a number %% Guess Number Game while(1) count=0; guess=input('Guess a number between 0...
Game to guess a number %% Guess Number Game while(1) count=0; guess=input('Guess a number between 0 to 10 '); if(R>guess) disp('Your guess is too small') elseif (R<guess) disp('Your guess is too large') elseif (R==guess) disp('You are correct! It is ');guess R=floor( rand()*10 ); end count=count+1; if(count==3) break; end end You need to modify this code: (1)Player fails the game if you cannot make it within 3 tries. (2)Player can do this game up to 10 times. (3)If player input is...
Write a program that asks the user to guess a random number. The program should use...
Write a program that asks the user to guess a random number. The program should use a loop to prompt the user for the guess then display if the guess is 'too high' or 'too low'. In the end, display how many times it took to guess the number. Use the attached template.   // Chapter 5 - Lab exercise, Random Number Guessing Game // // Name: // #include <iostream> #include <cstdlib> // Needed to use random numbers #include <ctime> //...
In this module you learned about making decisions. You learned about the syntax and rules used...
In this module you learned about making decisions. You learned about the syntax and rules used to develop programs containing decisions and how the logic can make your programs more robust. Draw a flowchart for a program that shows the logic for a program that generates a random number. The program will simulate tossing coin. The program should generate a random number(0 and 1). If the random number is 0, then it should display the word "Heads". If the random...
This is an intro to Java question. Please include pseudo code for better understanding. I am...
This is an intro to Java question. Please include pseudo code for better understanding. I am hoping to use this to do some reviewing. We are mainly focusing on input and output declarations and invoking API methods. Problem 6: Log It (10 points) Use API (Data Structure Algorithms) High-Low is a simple number guessing game where one player thinks of a random integer number between 0 to some maximum value and another player attempts to guess that number. With each...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT