Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Discover a wealth of knowledge from experts across different disciplines on our comprehensive Q&A platform. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.
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 hope you found what you were looking for. Feel free to revisit us for more answers and updated information. We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.