Day 9
Hello!
Today I learned how to make a loop, which is a function that keeps looping until it reaches what you want. I know that talking is difficult. Let me include the image and let's get into the explanation.
This is a model of the game, which is that the system will guess a random number from 0 to 100, and the user is required to guess this number until it reaches the same number and wins.
We start from line 7, and as we learned before, this line defines variables, and here I included 2 variables of the int type.
Line 8 is the question about guessing the number.
Line 9 is the beginning of the loop, so if I don't guess the number correctly, it will keep going back from this step again until I guess the number correctly.
Line 12 tells the user to guess the number.
Line 13 receives the number from the user. Line 14 checks if the number is larger than the number guessed by the system. In this case, it prints in the output very large as in line 15.
Line 17 checks if the number chosen by the user is less than the number chosen by the system. It prints in the output very small as in line 18.
But if it is not larger or smaller than the number chosen by the system, it will be the number chosen by the system and it prints in the output you win!!.
As for line 23, it ends the loop if the user's guess is equal to the system's guess and the game ends here and starts again with a new number
تعليقات
إرسال تعليق