Skip to main content

Exercises 5.7 Exercises


Use a for statement to print 10 random numbers.

import random

howmany = 10
for counter in range(howmany):
    arandom = random.random()


Repeat the above exercise but this time print 10 random numbers between 25 and 35, inclusive.


The Pythagorean Theorem tells us that the length of the hypotenuse of a right triangle is related to the lengths of the other two sides. Look through the math module and see if you can find a function that will compute this relationship for you. Once you find it, write a short program to try it out.

import math

side1 = 3
side2 = 4
hypotenuse = math.hypot(side1,side2)


Search on the internet for a way to calculate an approximation for pi. There are many that use simple arithmetic. Write a program to compute the approximation and then print that value as well as the value of math.pi from the math module.

You have attempted of activities on this page.