Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
10327 views
ubuntu2004
Kernel: Python 3 (system-wide)

Exercise 23.1

In Exercise 3.5 you calculated the circumference and area of a circle of radius 5.4 cm.

Repeat the exercise but using the value of π\pi in the math module.

import math circumference = 2 * math.pi * 5.4 print(circumference)
33.929200658769766

Exercise 23.2

Using the statistics module, calculate the mean and standard deviation of the following list of bat wingspans. The documentation for the statistics module is here.

import statistics wingspans = [20.4, 21.1, 17.1, 16.7, 24.4, 17.8, 20.1, 21.2, 20.8, 18.4, 20.0, 20.8, 19.4, 16.9, 18.0, 18.5, 18.0, 17.5, 18.7, 21.6, 21.6, 20.1, 20.6, 22.0, 20.0, 16.8, 24.2, 15.4, 21.2, 22.2, 26.1, 21.5, 18.9, 18.5, 19.9, 20.9, 18.4] print(statistics.mean(wingspans)) print(statistics.pstdev(wingspans))
19.883783783783784 2.259695448687304

Exercise 23.3

  1. Search online for a module to randomly choose an item from a list.

  2. Use the module to randomly choose an item from the following list.

  3. Print the chosen item.

import random cities = ['Doha', 'Vancouver', 'Entebbe', 'Pokhara', 'Whangarei'] print(random.choice(cities))
Entebbe