Practice questions for the arithmetic operators



There are seven different types of arithmetic operators used in python. And it is particularly used for mathematical computations. Here are the seven different types of operators;

  • Addition (+)
  • Subtraction (-)
  • Division (/)
  • Multiplication (*)
  • Exponents (**)
  • Floor division (//)
  • Modulus (%)

To explore more on an arithmetic operator, check here

Question 1:

Write a simple basic calculator program in python?
Direction:
Your program should be dynamic where it should accept two numbers from a user and do all the following calculations:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. modulus
6. Exponents
7. Floor division

Source code:

a = float(input("Enter num a:"))
b = float(input("Enter num b:"))

add = a + b
sub = a - b
pro = a * b
div = a / b
floor_division = a // b
exponents = a ** b
mod = a % b

print(f"Addition of {a} + {b} = {add}")
print(f"Subtraction of {a} - {b} = {sub}")
print(f"Product of {a} x {b} = {pro}")
print(f"Division of {a} / {b} = {div}")
print(f"Floor division of {a} // {b} = {floor_division}")
print(f"Exponents of {a} ** {b} = {exponents}")
print(f"Modulus of {a} % {b} = {mod}")

Output:

Enter num a:5
Enter num b:6
Addition of 5.0 + 6.0 = 11.0
Subtraction of 5.0 - 6.0 = -1.0
Product of 5.0 x 6.0 = 30.0
Division of 5.0 / 6.0 = 0.8333333333333334
Floor division of 5.0 // 6.0 = 0.0
Exponents of 5.0 ** 6.0 = 15625.0
Modulus of 5.0 % 6.0 = 5.0


Question 2:

Write a python program that takes in a student name, class, and section. It should also take in five subject marks of the students and find the total mark and percentage. Display a result in such a way that their name, class, section, and percentage are printed.

Source code:

name = input("Enter name:")
clas = input("Enter class:")
section = input("Enter section:")
eng = float(input("Enter English mark:"))
dzo = float(input("Enter Dzongkha mark:"))
math = float(input("Enter Math mark:"))
his = float(input("Enter History mark:"))
geo = float(input("Enter Geography mark:"))

total_mark = eng + dzo + math + his + geo
percentage = total_mark / 5

print("\n---------Printing result-------------")
print("Name:", name)
print("Class:", clas)
print("Section:", section)
print("Percentage:", percentage,"%")

Output:

Enter name:Sonam
Enter class:10
Enter section:A
Enter English mark:78
Enter Dzongkha mark:90
Enter Math mark:87
Enter History mark:56
Enter Geography mark:67

---------Printing result-------------
Name: Sonam
Class: 10
Section: A
Percentage: 75.6 %