-
Notifications
You must be signed in to change notification settings - Fork 42
/
arithmetic.py
29 lines (24 loc) · 1.43 KB
/
arithmetic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# ------------------------------------------------------------------------------------
# Tutorial: What are arithmetic operators and how to use them.
# ------------------------------------------------------------------------------------
# Arithmetic operators all you to perform mathematical calculations in Python.
a = 5
b = 3
a + b # addition - adds two operands together
a - b # subtraction - subtracts the right operand from the left
a * b # multiplication - multiplies two operands
a / b # division - divides left operand from right
a % b # modulus - remainder of the division of left operand by the right
a ** b # exponential - left operand raised to the power of the right
a // b # floor division - division that results in whole number adjusted to the left in the number line
# When doing more complicated arithmetic, brackets are useful to seperate calculations.
c = 10
d = 12
(((a + b) / c) * d) # (a + b) will be performed first
# ------------------------------------------------------------------------------------
# Challenge: list challenges to be completed here. minimum of one challenge per tutorial
# ------------------------------------------------------------------------------------
# 1. Ask a user to input two numbers. Print these two numbers and show:
# (a) the sum of the numbers
# (b) the divison of the numbers (both a / b and b / a)
# (c) the modulus of the numbers (both a % b and b % a)