At Westonci.ca, we provide reliable answers to your questions from a community of experts. Start exploring today! Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately. Our platform offers a seamless experience for finding reliable answers from a network of knowledgeable professionals.

I have a project that i started working on Python 3 but i am not quite sure of what to do next.. here are the steps :

Write a program to play a “Guess My Number” game.

In the game, the computer should generate a random whole number between 1 and 20. The player will then have to guess the computer’s number.

Stage 1: Write your program to create and store a random number then use a conditional loop to let the player keep guessing until they get it right. When the player guesses correctly, they should see a message saying “Correct, my number was … “, telling the player the correct answer.

Stage 2: Use a running total inside the loop to keep a count of how many guesses the player had. When the player gets the right answer, tell them how many guesses it took.

Stage 3: Use conditions (IF..THEN..ELSE) inside the loop to tell the user if their guess was too low or too high

Stage 4: Give the player a score at the end of the game - calculate the score using this method - (number of guesses / 20) * 100 - the answer should be rounded to 0 decimal places.



Here is what i started by doing:

import random

num = random.randit(1,20)

guess = int(input("Guess the number : "))

guesses_left = 10

while guesses_left < 0:
while True:
guess = input("guess a number between 1 and 10: ")
print(str(guesses_left) + " incorrect guesses left.")
if guess != num:
print("That is not my guess, try again")
elif not guess.islower():
print("The guess is lower")
else :
print("Correct, my number was" + str(num))
guesses_left = guesses_left - 1

Thank you so much for your help and advice, i appreciate it.


Sagot :

Answer:

I'll write some pseudo-code, you can convert it into Python. // means I've wrote a comment explaining what is going on. Don't overcomplicate things when you write code!

Start

Declare Num as Integer // Defines a variable called Num

// Here you put your code to generate a random number

Num = random number between 1 to 20

Declare Guess as Integer

Declare CorrectGuess as Boolean // Boolean variables are either true or

                                                             false.

CorrectGuess = False

// To keep track of how many guesses it takes them

Declare GuessCount as Integer = 0

Declare Score as Real = 0 // Real means the number can be a decimal.

While CorrectGuess = False:  // keep looping until correct.

          GuessCount = GuessCount + 1  // Increases the guess count by 1.

          output("What's your guess?")    // asks the user what their guess is.

          input(Guess)                               // Allows the user to input their guess.

          If Guess = Num Then                 // Using a condition to decide if the

                                                                  guess is correct.

                  output("Correct, my number was " + Num") // correct output

                  //output GuessCount

                  output("It took you " + GuessCount + " guesses!")

                  CorrectGuess = True  // Now the while loop won't run again.

          Else If Guess > Num Then // If the guess was larger than the number

                   output("Your guess was too large! Try again.")

          Else If Guess < Num Then // If the guess was smaller than the number

                   output("Your guess was too small! Try again.")

          Else

          End If

End While

Score = (GuessCount / 20) * 100 // Calculate the users score.

Round(Score) // Round the score to 0 decimal places.

End

Hope you can understand this. I think followed all of the stages and if something is incorrect don't hesitate to tell me.