Numbers and Math in Python

1 minute read

Numbers and Math

This exercise has lots of math symbols. Here are the names:

The symbol The Name The Work
+ plus Addition
- minus Subtraction
* asterisk Multiplication
% percent Division
< less-than compare
> greater-than compare
<= less-than equal-to compare
>= greater-than equal-to compare

Let’s write a piece of code and check the outputs,

# normal maths
print("Apples", 3+4+2/3)   # fist-case
print("Banana", 10*6+2-3)  # second-case

# comparison
print(3 + 9 < 9 - 8)       # third-case

# modulus action
print(15 % 4)              # fourth-case

So, run the code now and try to understand the output


Apples 7.666666666666667
Banana 59
  • In the first case & second case, the print() function has one string and one mathematical expression separated by comma, where the mathematical expression is solved by the normal BODMAS rule.
  • In the third case, we had a comparison and it returns Boolean datatype. Which means binary (0 & 1) . True is treated as 1 and False is treated as 0.
  • In the fourth case we are dealing with the % operator which simply means modulus but not percent here. In simpler words a % b means, the reminder obtained when a is divided by b. For example here 15 is divided by 4 and the reminder obtained is 3.

Exercise your way out

Q - You are given a list of marks(out of 100) for a student. Your aim is to print the corresponding percentage of the student.

​ Mathematics - 50

​ Physics - 85

​ Social Science - 60

​ Also print the total aggregate percentage.

We are here to help ! Be sure to check our website and don’t hesitate to ask any questions on our community platform. We provide personal mentoring and teaching too, in order to upgrade your skills. Vist to get started.

Spotted a bug ? Great job, you found a bug. Please report it to us in our mail and we’ll fix it as soon as possible.