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

Exercise 3.1

In your head, or on paper, work out the following arithmetic as you would expect Python to do it using the rules of precedence.

  • 5 * 5 - 5 = ?

  • 10 - 2 * 3 = ?

  • 20 + 5 * 2 - 10 = ?

  • 4 + 4 / 2 = ?

  • 2 * 5 ** 2 = ?

  • 9 / 3 ** 2 = ?

Check your answers by typing them into the code cell below.

print(5 * 5 - 5) print(10 - 2 * 3) print(20 + 5 * 2 - 10) print(4 + 4 / 2) print(2 * 5 ** 2) print(9 / 3 ** 2)
20 4 20 6.0 50 1.0

Exercise 3.2

What are the types of each of the following numbers?

  • -6

  • 10.3

  • 99.0

  • -1.0

Check your answers in the code cell below.

type(99.0)
float

Exercise 3.3

  1. What type of number do you get if you do 4 / 2?

  2. What type of number do you get if you do 4 // 2?

Check your answer below.

type(4//2)
int

Exercise 3.4

Round the following floats to the given number of decimal places.

  • 34.2694 to 2dp

  • -1.4 to 0dp

  • 1024.234 to 1dp

print(round(34.2694, 2)) print(round(-1.4)) print(round(1024.234, 1))
34.27 -1 1024.2

Exercise 3.5

What are the circumference and area of a circle of radius 5.4 cm rounded to 1 decimal place?

If you've forgotten what the circumference and area of a circle are use google.

print(round(2*3.14*5.4, 1)) print(round(3.14*5.4**2, 1))
33.9 91.6

Exercise 3.6

In the code cell below calculate the average of the following set of numbers to 2dp:

11, 11, 13.5, 7.5, 13.5, 22.5
round((11+11+13.5+7.5+13.5+22.5)/6, 2)
13.17

Exercise 3.7

Using Python code calculate what 321 minutes is in hours and minutes? (E.g., 61 minutes is 1 hour and 1 minute.)

Find the remainder of the following:

  • 592\frac{59}{2}

  • 1002\frac{100}{2}

print(321//60) print(321%60)
5 21