Question

how would i write my code in Pseudocode? I am pretty much a beginner, therefore this...

how would i write my code in Pseudocode? I am pretty much a beginner, therefore this is my first major computer science assignment and im not really understanding the written way of code.. please help and explain. Thank you!

this is my working code:

# Guess The Number HW assignment
import random

guessesTaken = 0
names=[]
tries=[]
print("Welcome! ")
question = input("Would you like to play the guessing game? [Y/N]")
if question == "N":
print("Sorry to see you go so soon, bye for now!")
else:
print("..loading..")
while question!='q':
print("Well, I am thinking of a number between 1 and 20.")

number = random.randint(1, 20)
# -------------------------------------------------------------------
guess = 21
while guess != number and guessesTaken < 40:
print("Take a guess.")
guess = input()
while (guess.isdigit() == False):
guess = input("Guess needs to be a whole number.")
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print("Your guess is too low.")
if guess > number:
print("Your guess is too high.")

if guess == number:
print("Good job, you guessed my number! What is your name?")
name = input("Enter name:")
names.append(name)
tries.append(guessesTaken)
guessesTaken = 0
  
else:
number = str(number)
print("Nope. The number I was thinking of was " + number)
guessesTaken = 0

question = input("\nLets play again (press q to quit or enter to continue) ")
if (question == "q"):

for i in range(len(names)):
print(names[i],tries[i])
  

  

minGuess=min(tries)
ind=tries.index(minGuess)
name=names[ind]
print()
print(name,'won with the least amount of tries',minGuess)

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

Psuedo Code:

Begin

Set guessesTaken = 0

Set names = []

Set tries=[]

Read if user wishes to play the game (Y/N) into variable question

If question = “N”

Print goodbye message

Else

                While question != “q”

Generate a random number between 1 and 20 and store in variable number

Declare and set guess to 0

                               While guess != number and guessesTaken < 40

                                                 Read the user guess into guess varaible

                                                Repeat until guess is not a digit

                                  Print error message and read another number from user

             increment guessesTaken by 1

                                           if guess < number:

                                                                                print "Your guess is too low."

                                          if guess > number:

                                                                                print "Your guess is too high."

                                          if guess = number:

                   print "Good job, you guessed my number! What is your name?"

                                                                               Read the user name

                                           Store the name in names array

                               Store the guessTaken in tries array                                         

                               Set guessesTaken to 0

                               End While

                             If guessesTaken = 40

                                                                Print the number generated

                                                                Set guessesTaken to 0

                Read if user wishes to continue or enter q to quit into question variable

                           If question = "q"

   For i in range(len(names))

                Print all names and tries

   End For

                           Get min(tries)

                           Get name of player with minimum guessesminGuess

                           Print name who won with the least amount of tries

             End While

Stop

Program: Code is explained using comment

# Guess The Number HW assignment
import random

# declare a variable that hold the count of number of guesses
guessesTaken = 0
# declare an array to hold the names of the players
names=[]
# declare an array to store the number of tries of each player
tries=[]
# display a welcome message
print("Welcome! ")
# prompt and read if user wants to play the game
question = input("Would you like to play the guessing game? [Y/N]")
# display a message and terminate program if user enters n
if question == "N":
    print("Sorry to see you go so soon, bye for now!")
# else start the game
else:
    print("..loading..")
    # run a loop to repeat the game until q is entered by the user
    while question!='q':
        print("Well, I am thinking of a number between 1 and 20.")
        # generate a random number between 1 and 20
        number = random.randint(1, 20)
        # -------------------------------------------------------------------
        guess = 21
        # run a loop to repeatedly until the user guesses correct number or the number of guesses is less than 40
        while guess != number and guessesTaken < 40:
            # prompt and read the users guess
            print("Take a guess.")
            guess = input()
            # run a loop until a valid guess is entered by the user
            while (guess.isdigit() == False):
                guess = input("Guess needs to be a whole number.")
            # convert the guess into an integer
            guess = int(guess)
            # increment the count of number of guesses
            guessesTaken = guessesTaken + 1
            # if guess is less than the generated number display appropriate message
            if guess < number:
                print("Your guess is too low.")
            # if guess is greater than the generated number display appropriate message
            if guess > number:
                print("Your guess is too high.")
            # if guess is the generated number
            if guess == number:
                # display appropriate message and read the user name
                print("Good job, you guessed my number! What is your name?")
                name = input("Enter name:")
                # store the name in array
                names.append(name)
                # store the number of guesses in the array
                tries.append(guessesTaken)
                #reset number of guesses to 0
                guessesTaken = 0
        # if the number of guesses reached 40
        if guessesTaken == 40:
                # display the number generated and reset number of guesses to 0
                number = str(number)
                print("Nope. The number I was thinking of was " + number)
                guessesTaken = 0
        # prompt and read if user wishes to continue or quit
        question = input("\nLets play again (press q to quit or enter to continue) ")
        # if the user wants to quit
        if (question == "q"):
            # display the names of all the players and the tries they took
            for i in range(len(names)):
                print(names[i],tries[i])
            # get the minimum number of guesses  
            minGuess=min(tries)
            ind=tries.index(minGuess)
            # get the name of the player who had minimum number of guesses
            name=names[ind]
            print()
            # display the name of the player who won with minimum number of guesses
            print(name,'won with the least amount of tries',minGuess)


Output:

Program Screenshot:

Add a comment
Know the answer?
Add Answer to:
how would i write my code in Pseudocode? I am pretty much a beginner, therefore this...
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
  • on python i need to code a guessing game. After the player has guessed the random...

    on python i need to code a guessing game. After the player has guessed the random number correctly, prompt the user to enter their name. Record the names in a list along with how many tries it took them to reach the unknown number. Record the score for each name in another list. When the game is quit, show who won with the least amount of tries. this is what i have so far: #Guess The Number HW assignment import...

  • In python how could I update my code to tell me the number of guesses it...

    In python how could I update my code to tell me the number of guesses it took my to get the correct number here is my working code so far import random number = random.randint(1,100) total_guess = 0 while total_guess<=100: guess = int(input("what is your guess?")) print (guess) total_guess = total_guess + 1 if guess<number: print("Too low") if guess>number: print("Too high") if guess==number: print("Correct!") break

  • This is python code I am having trouble with the both winning messages printing if the...

    This is python code I am having trouble with the both winning messages printing if the user guesses in 1 try. 1 message or the other should print depending on the number of guesses not both. Thank you for your help! import random answer = 5 tries = 0 user_guess = "" while True: user_guess = int(input("enter a number between 1 and 10: ")) tries = tries + 1    if user_guess == answer: print ("You win! \nIt took you",...

  • FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called...

    FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called guess my number.") print("The rules are: ") print("I think of a number and you'll have to guess it.") guess = random.randint(1, 5) print("You will have " + str(guess) + " guesses.") YourNumber = ??? unusedguesses=int(guess) while unusedguesses < guess:     if int(YourNumber) == number:         print("YAY, You have guessed my number")     else:         unusedguesses=int(guess)-1         if unusedguesses == 0:              break         else:             print("Try again!") print("The number was ", str(number))

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

  • Can someone please rewrite this code using a while loop? Please write it in python. #The...

    Can someone please rewrite this code using a while loop? Please write it in python. #The winning number my_number = 12 #variable for the input name user_n = input("Hello! What is your name?") #Ask the user print("Well",user_n,": I am thinking of a number between 1 and 20." + "Take a guess.") user_n = float(input("Take a guess.")) #if statements if user_n == my_number: print("Good job" ,user_n, "You guessed my number!") if user_n > my_number: print("Your guess is high. You lose.") if...

  • using python in eclipses Question I am attempting to solve My attempt... 1. Add a new...

    using python in eclipses Question I am attempting to solve My attempt... 1. Add a new module named twenty_questions_class to the package library. 2. Define a class named TwentyQuestions in the module with an instance constructor and a method. a. The instance constructor _init is used to create an instance of the TwentyQuestions class with a value for the RANGE. b. The method named play lets the user play the game. For example, I am thinking of a secret number...

  • Write a JAVA program that plays a number guessing game with the user. A sample run...

    Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...

  • I need help on creating a while loop for my Java assignment. I am tasked to...

    I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

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