IDNLearn.com is your go-to platform for finding accurate and reliable answers. Our experts provide timely and accurate responses to help you navigate any topic or issue with confidence.
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.
We appreciate your contributions to this forum. Don't forget to check back for the latest answers. Keep asking, answering, and sharing useful information. Your search for answers ends at IDNLearn.com. Thanks for visiting, and we look forward to helping you again soon.