How To Add, Multiply, And Subtract Two Numbers | Python 4 You | Lecture 200

Опубликовано: 17 Январь 2025
на канале: Rehan Blogger
3
0

In Python, you can perform basic arithmetic operations such as addition, subtraction, and multiplication on numbers with ease. Here's how you can do it:

Addition:
To add two numbers in Python, you simply use the + operator. Here's an example:
python code
num1 = 5
num2 = 3
result = num1 + num2
print("Sum:", result)
In this code, num1 and num2 are the numbers you want to add, and the result is stored in the result variable.

Subtraction:
To subtract one number from another, you use the - operator. Here's an example:
python code
num1 = 10
num2 = 4
result = num1 - num2
print("Difference:", result)
In this code, num1 and num2 are the numbers you want to subtract, and the result is stored in the result variable.

Multiplication:
To multiply two numbers, use the * operator. Here's an example:
python code
num1 = 6
num2 = 7
result = num1 * num2
print("Product:", result)
In this code, num1 and num2 are the numbers you want to multiply, and the result is stored in the result variable.

Here's the complete code to add, subtract, and multiply two numbers:
python code
Addition
num1 = 5
num2 = 3
add_result = num1 + num2
print("Addition:", add_result)

Subtraction
num1 = 10
num2 = 4
sub_result = num1 - num2
print("Subtraction:", sub_result)

Multiplication
num1 = 6
num2 = 7
mul_result = num1 * num2
print("Multiplication:", mul_result)

When you run this code, it will calculate the sum, difference, and product of the specified numbers and print the results. You can modify the values of num1 and num2 to perform these operations with different numbers.#python4 #pythontutorial #pythonprogramming #python3 #pythonforbeginners #pythonlectures #pythonprograms #pythonlatest #rehanblogger #python4you #pythonlatestversion #pythonlatestversion Learn python3.12.0 and latest version of python3.13. If you are searching for python3.13.0 lessons, you are at the right place as this course will be very helpful for python learners or python beginners.