Site icon Student Projects Live

Subtraction

Subtraction

The provided Python code demonstrates the implementation of subtraction operations. Two examples are given to showcase subtraction with both integers and floating-point numbers. In the first example, two integer variables, a and b, are subtracted, and the result is stored in the variable result. The second example involves floating-point numbers, x and y, with the subtraction result stored in the variable result_float. The print function is used to display the subtraction expressions along with their respective results. This code provides a basic illustration of how subtraction can be performed in Python, showcasing its flexibility to handle both integer and floating-point arithmetic.


Source code

# Example 1
a = 10
b = 5
result = a - b
print(f"{a} - {b} = {result}")

# Example 2
x = 15.5
y = 7.2
result_float = x - y
print(f"{x} - {y} = {result_float}")

Description

  1. Variable Assignment:

a = 10 b = 5 x = 15.5 y = 7.2

  1. Subtraction Operation:

result = a - b result_float = x - y

  1. Print Statements:

print(f"{a} - {b} = {result}") print(f"{x} - {y} = {result_float}")

  1. Output:

10 - 5 = 5 15.5 - 7.2 = 8.3

In summary, the code initializes variables with specific values, performs subtraction operations on both integers and floating-point numbers, and then prints the results, demonstrating the basic usage of the subtraction operator in Python.


Screenshot


Download

Exit mobile version