Libraries
Libraries are collections of code that other people have written. Video games often use massive libraries (for example: game engines) to create the epic water reflections, 3-D graphics, etc.
We are going to start a bit smaller by just generating random numbers. (After all, random numbers are the basis of most games).
Random library
We can use a library by writing
import
and then the library name. EXAMPLE :
import random
myNumber = random.randint(1,100)
print(myNumber)
How random works
In the code below, I have created a variable, 'myNumber'. I am making it equal to a random number given to me by the randint
(random integer) library. I add the lowest number (1) and the highest number (100) that can be picked and the computer will generate a number at random.
Comments
Post a Comment