Python Practical Assignment 2.1

Write a Python Program to Perform Arithmetic Operations Using Variables

Introduction

Arithmetic operations in Python are used to perform basic mathematical calculations like addition, subtraction, multiplication, and division. In this program, we will use variables to perform these operations.


Logic to Write the Code

  1. Start the program.
  2. Assign values to two variables.
  3. Perform arithmetic operations (addition, subtraction, multiplication, division).
  4. Print the results using the print() function.
  5. End the program.

Source Code (Beginner Friendly)

# Python program to perform arithmetic operations using variables

# Assigning values to variables
num1 = 10
num2 = 5

# Performing arithmetic operations
addition = num1 + num2
subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2

# Displaying the results
print("Addition:", addition)
print("Subtraction:", subtraction)
print("Multiplication:", multiplication)
print("Division:", division)

Sample Output

Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2.0

Viva Questions with Answers

1. What are arithmetic operators in Python?

Arithmetic operators are symbols used to perform mathematical operations like +, -, *, and /.

2. Which operator is used for multiplication in Python?

The * operator is used for multiplication.

3. What is the result type of division in Python?

Division (/) always returns a float value.

4. Can we use variables in arithmetic operations?

Yes, variables can store numbers and be used in calculations.

5. What will happen if we divide a number by zero?

It will give a ZeroDivisionError.


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top