dice = random.randint(1,6)
2. rand decimal.py
decimal = random.uniform(0,1)
percent = random.uniform(0,100)
#round percent to 2 decimal places:
rounded = round(percent, 2)
4. random choice.py
population = ["TEN", "JACK", "QUEEN", "KING", "ACE"]
card = random.choice(population)
5. random sample.py
population = [1,2,3,4,5,6,7,8,9]
sample_of_three = random.sample(population, 3)
#print each element in list:
for each in sample_of_three:
Samples 4 and 5 above use Lists and For Loops which will be covered later on.
Don't worry about these now - they are located here as reference material for future use.
- Generate a random number between 2 and 21.
- write a program that outputs the roles of 2 dice. Challenge: Sum the total of the two dice (so this could be used in monopoly).
- write a program that inputs a whole, positive integer number, then generates a random number between 1 and the number inputted (display this to the screen)
- Write a program that generates 2 random numbers between 1 and 10, and then finds the product of these 2 numbers. Your program should produce output that looks something like this, but with random numbers each time:
Number one: 5
Number two: 7