Arithmetic Write a program that prints out the results of at least one calculati
ID: 3747259 • Letter: A
Question
Arithmetic Write a program that prints out the results of at least one calculation for each of the basic operations: addition, subtraction, multiplication, division, and exponents. . Order of Operations Find a calculation whose result depends on the order of operations Print the result of this calculation using the standard order of operations Use parentheses to force a nonstandard order of operations. Print the result of this calculation Loeg Decimals On paper, o.1-0.2-0.3. But you have seen that in Python, 0.1-0.2 Find at least one other calculation that results in a long decimal like this Neat ArithmeticExplanation / Answer
Answer:
A python program is written for different sections in the questions. In the below python program multiple functions are created to perform each section as mentioned in the question.
arithmetic() --> Function provides an example for different arithmetic operations. As part of the example, two inputs to be provided and computed output will be displayed on screen.
orderOfExecution() --> Function provides an example for BODMAS operations.
longDecComputaion() --> Function provides an example for long decimal operations.
As part of the program documentation provided as the comments which help in understanding each statement of the program.
Python program is as below:
-------------------------------------------------------------------
# This program is written for Python 3.0
# This portion of program covers Arithmetic section.
def arithmetic():
print("This result covers Arithmetic section")
a = int(input("Input first number: ")) #Input first number used
b = int(input("Input Second number: ")) #Input second number used
print("Addition of two numbers: ", a+b)
print("Subtraction of two numbers: ", a-b)
print("Multiplication of two numbers: ", a*b)
print("Division of two numbers: ", a/b)
print("Exponent of two numbers: ", a**b)
# This portion of the program covers Order of execution section.
def orderOfExecution():
# Order of arithmetic operation follows BODMAS Order.
#B - Bracket operations will be evaluated first
#O - Of operations will be evaluated second
#D - Division operations will be evaluated third
#M - Multiplication operations will be evaluated fourth
#A - Addition operations will be evaluated fifth
#S - Subtraction Operations will be evaluated sixth
print("This result covers Order of Execution section")
#In below print statement standard order is followed for arithmetic operations.
# 8/2 will be performed first making result = 4
# 3*4 will be performed second making result = 12
# Then 10 - 4 + 12 = 18
print("Standard Order of Execution: ", 10-4+3*8/2)
#In below print statement non standard order is followed due to usage of bracket.
# (4+3) will be performed first making result = 7
# (10-) will be performed second making result = 3
# Then 3*8/2 = 3*4 = 12
print("Non Standard Order of Execution : ", (10-(4+3))*8/2)
# This portion of program covers long decimal computation.
def longDecComputaion():
print("This result covers Long decimals section")
print("Long decimal computation : ", 0.12+0.02)
arithmetic()
print("")
orderOfExecution()
print("")
longDecComputaion()
------------------------------------------------------------------------------------------
The output of the program as below:
This result covers Arithmetic section
Input first number: 5
Input Second number: 8
Addition of two numbers: 13
Subtraction of two numbers: -3
Multiplication of two numbers: 40
Division of two numbers: 0.625
The exponent of two numbers: 390625
This result covers Order of Execution section
Standard Order of Execution: 18.0
Non Standard Order of Execution : 12.0
This result covers Long decimals section
Long decimal computation : 0.13999999999999999
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.