#WSQ03 – Pick a Number

Here are the instructions:

Write a program that picks a random integer in the range of 1 to 100.There are different ways to make that happen, you choose which one works best for you.It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.You might want to check that your program doesn’t always use the same random number is chosen and you should also split your problem solving into parts. Perhaps only generate the random number and print that as a first step.

 

  1. I found how to ask Python for a random integer using https://www.tutorialspoint.com/python/number_randrange.htm. You only need to import random and call for random.randrange(first number, last number)
  2. I only printed the random number r to make sure I know what it was and that the program was functional.
  3. x is the number the user is guessing each time
  4. trial is the number of trials: every time the user guesses a wrong number (higher or lower than the random number generated by Python), a trial is counted.
  5. while was the most important input to my program! Indeed, I read this article https://www.tutorialspoint.com/python/python_while_loop.htm and everything was clearer! While repeat the block forever. The way to stop it is the print!

 

Leave a comment