Post a Python program with a scenario that accepts at least three values as input, performs some computation and displays at least two values as the result. The program must include an if statement that performs different computations based on the value of one of the inputs. Include comments in your program that describe what the program does. Also post a screen shot of executing your program on at least two test cases.
The program can be designed as follows:
The python program:
#function that will return the sum and product of two numbers
#the parameters are a sign and two numbers
def func(sign,num1,num2):
#sign is positive
if sign > 0:
ans = num1 * num2
sum1 = num1 + num2
#sign is negative
else:
ans = num1 * num2 * -1
sum1 = (num1 + num2) * -1
return ans,sum1
#calling func with negative sign and two numbers
product,addition = func(-1,3,4)
print("Product: %i" %product)
print("Addition: %i" %addition)
#calling func with positive sign and two numbers
product2,addition2 = func(1,4,6)
print("\nProduct2: %i" %product2)
print("Addition2: %i" %addition2)
Code snippet:
Output:
Get Answers For Free
Most questions answered within 1 hours.