External Exam Download Resources Web Applications Games Recycle Bin

Random Numbers

randint.py

import random 
dice = random.randint(1,6) 
print(dice)


rand decimal.py

import random 
decimal = random.uniform(0,1) 
print(decimal)


rounding.py

import random 
percent = random.uniform(0,100)

#round percent to 2 decimal places:
rounded = round(percent, 2)

print(rounded)


  1. Generate a random number between 2 and 21.

  2. 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).

  3. 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)

  4. 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 
    Product: 35