Day Four - Randomisation and Python Lists Flashcards
How to access the random library?
import random
Can you import your own module?
Yes, just create a file and them go to another (program) and type: ‘import + name of the file’.
How can you make a random float number?
Type: random.random()
and them multiply it by 5 (or any other number).
How can you make a random int number?
Type: random.randint()
Put the two numbers inside.
How to make a list?
You can set them by typing a = [smt, smt2]
two square brackets.
How to access a specific item inside of it?
print(a[1])
by using the brackets and the n° of the position inside of it.
How to add an element at the end of the list?
You can use .append.
ex - a.append(element).
How can you use the split to split after a specific parameter?
Put the parameter inside the parenthesis.
a.split(“, “) (the parameter is the comma).