10. Working with numbers

  • Arithmetic operations are easy in Python
  • Common operators to use with numbers are as follows:
SymbolExampleOperation
()(a+b)/cParenthesis
*a*bMultiplication
/a/bDivision
%a%bModulus
+a+bAddition
a-bSubtraction
=a=bAssignment
a = input("Enter a whole number: ")
a = int(a)
square = a * a
print(square)

Tasks

  1. Write a program that asks for the width and height of a rectangle, and outputs the area
  2. Write a program that asks for the radius of a circle, and outputs the area
    1. Assume pi (π) is 3.14159
    2. The formula to calculate the area of a circle is πr2
    3. Save, print and label your code

Extension Task

Can you modify the programs above to calculate the volume of the three dimensional versions of these shapes? A cuboid and a cylinder.