Python Modules Exercises

  1. What does the following Python scripts display?
    1. print( random.random() )
    2. import random
      print( random.random() )
      
    3. import random
      print( random.random() * 5 )
      
    4. import random
      print( random.random() * 3 + 2 )
      
    5. import random
      print( random.uniform( 22.1, 33.2 ) )
      
    6. import random
      print( random.randrange( 10 ) )
      
    7. import random
      print( random.randrange( 5, 10 ) )
      
  2. Replace the blank sections with Python code to complete the following script:
    MAX_NUM = 2**32
    humanGeneratedNumber = int(input("Please enter a number between 0 and " + str(MAX_NUM) + ": "))
    print( "Here's a 'random' real number between 0.0 and 1.0:", ____________________________________)
    print( "Here's a 'random' whole number (an int) between 0 and 100: ", ____________________________________)
    
  3. Columbus gets a lot of rain. It rains up to 10.5 inches in one day. Write a Python script that displays a simulated amount of rainfall for Columbus.
  4. You're making a maze game with trap doors. Each maze is randomly generated with 3 to 5 trap doors. Write a Python script that calculates and displays the number of trap doors for 100,000 mazes.