In: Computer Science
- Part 2 – 4 Desk Checking Exercises – these are 3 programs (pseudocode) that are working and 1 program (Python). Explainthe intent of the pseudocode / program. If you use test data, note the test data. . You are NOT trying to find mistakes.
What does this do? Desk
Checking #2: Explain the intent of this
pseudocode. Be as specific as possible.
List the data you use as the example data.
Use this textbox to explain the pseudocode/ code intent. Include any test data used: |
start
guess number between 1 and 100
while guess is not correct
if guess is too high
guess a number lower than the previous guess
else
guess a number higher than the previous guess
endif
endwhile
player wins
stop
Here we are trying to code a number guessing game. Here firstly, as we start the game, the program starts executing We assign a variable containing guess no beforehand. Thereafter, It takes input from us that should lie within the range 1 to 100. As we enter the number, it keeps on comparing with the preassigned guess number using conditional while loop and keeps on reiterating through it until we get the correct answer. That means,Now if our entered number is greater than the correct one, it will ask us to re-enter a number lower than the previous one or if it is lower than the correct one, it will ask us to re-enter a number greater than the previous one. As we enter a new number it will compare it with the preassigned number in a similar fashion. This will keep on continuing unless and until we arrive at the correct solution, after which we will exit the while loop and print that the payer wins!. For example, Let's assume, we entered 23. And the correct guess no assigned earlier in the program was 35 We will get into the while loop, So here it will first tell us to Enter a greater no. Suppose we enter 42 this time, It will ask us to re-enter a smaller number, Like this, the game will keep on continuing unless and until we enter 35. Once we enter 35, we will come out of the loop and win!.