Hello this time we are going to do a program to learn how to generate random numbers, use conditionals and a counter.
What does the program do? It picks a random integer in the range of 1 to 100 (you can do it on any other range if you want). It then prompts the user for a guess of the value, with hints of «too high» or «too low»
This is the program (there are different ways to generate a random number so feel free to search others and share them). then we initialize the counter (times = 0) and we give a value to the variable of the number (tr = 0) otherwise the program fails for the condition because it does not have a value to which compare the random number. I add to the conditional that if the number of tries is more than 5 the program prints «Sorry your attempts are over».
The lines 9 and 12 are the part of the counter (times=times+1) all that can be improve, but I did it like that to be clear about what is happening.
If you still have doubts check these pages : https://docs.python.org/2/library/collections.html
https://docs.python.org/3/library/collections.html
Thats it for this post thanks for read it. 🙂