WSQ03 -Libraries and ranges (Importing and using modules/libraries, and Creation and use of ranges in Python) (Python3)

--Originally published at Elu's Blog

For this assignment, this were 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.

This is my code:

Captura de pantalla 2017-02-13 a la(s) 16.30.45.png

Captura de pantalla 2017-02-13 a la(s) 16.33.42.png

Libraries are collections of tools and resources for programmers. They may include functions or data. To use a library in Python3, you have to use the word “import” before the name of the library, or you can use “from ‘name-of-the-library’ import ‘name-of-the-function'”. In my code I imported the ‘random’ library and I used the random.randrange() function which gets you a number from the range that you specify.

The range function in Python3 is used by telling it the first number and the last number of the range. Personally, I use it very often in for loops when using lists.