- Arithmetic operations are easy in Python
- Common operators to use with numbers are as follows:
| Symbol | Example | Operation |
|---|---|---|
| () | (a+b)/c | Parenthesis |
| * | a*b | Multiplication |
| / | a/b | Division |
| % | a%b | Modulus |
| + | a+b | Addition |
| – | a-b | Subtraction |
| = | a=b | Assignment |
a = input("Enter a whole number: ")
a = int(a)
square = a * a
print(square)
Tasks
- Write a program that asks for the width and height of a rectangle, and outputs the area
- Write a program that asks for the radius of a circle, and outputs the area
- Assume pi (π) is 3.14159
- The formula to calculate the area of a circle is πr2
- 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.