Explore Westonci.ca, the leading Q&A site where experts provide accurate and helpful answers to all your questions. Join our Q&A platform and connect with professionals ready to provide precise answers to your questions in various areas. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.
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 our answers were useful. Return anytime for more information and answers to any other questions you have. We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. Westonci.ca is committed to providing accurate answers. Come back soon for more trustworthy information.