Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Please write a python 3 program and show all outputs. PLEASE SEPARATE FILES A

ID: 3858806 • Letter: 1

Question

1. Please write a python 3 program and show all outputs.

PLEASE SEPARATE FILES ALSO SEE EXAMPLE OF PART ONE BELOW.

Complete the TODOs in waterregulation/controller.py and waterregulation/decider.py.
Complete the TODOs in waterregulation/test.py and waterregulation/integrationtest.py. A single integration test may be sufficient. However, your unit tests in test.py should include at least one test for each specified behavior.

python -m unittest waterregulation/test.py and python -m unittest waterregulation/integrationtest.py should have no failures.
Running coverage run --source=waterregulation/controller.py,waterregulation/decider.py -m unittest waterregulation/test.py; coverage report shows 90%+ coverage..
Satisfy the linter such that pylint waterregulation gives no errors and and flake8 waterregulation gives no errors. You may have to add docstrings to your test files.

______________________________________________________________________________________________________________________

Example Test for this program from part one. This is only an example of orginal instructions and output code.

Original Instructions

python -m unittest integration-test should have no failures. Don't edit integration-test.py, edit your code to make it pass.
Add unit tests to unit-test.py such that coverage run --source=calculator -m unittest unit-test; coverage report shows 100% coverage.
All of the tests in unit-test.py should pass.
Satisfy the linter such that pylint calculator gives no errors and flake8 calculator gives no errors. See (PEP257)[https://www.python.org/dev/peps/pep-0257/] if you'd like more information about docstrings. There are quite a few docstrings to add, but for this exercise you don't need to get too creative: """ this method adds two numbers """ is sufficient.

Bonus goal

One of our specs for calculator says the following:

The add, subtract, multiply, and divide methods shall both:
Return the result of the operation
Enter the result of the operation back into the calculator
This makes it possible to perform the following sequences of operations:
calculator.enter_number(2)
calculator.enter_number(3)
calculator.add()                      # Returns 5, and now 5 is now 'in the calculator'
calculator.enter_number(1)
calculator.subtract()               # Returns 4 because 5 - 1 = 4

_______________________________________________________________________________________________________

calculatorfuctions.py
"""calculator functions"""

def add(x, y):

    """ Add two numbers

    >>> add(1, 2)

    3

    >>> add(-7, 2)

    -5

    """

    return int(x) + int(y)

__________________________

calculatorusage.py
#!/usr/bin/env python3

"""calculator

    Usage:

    calculator.py 1 + 3

"""

____________________________

calculator_test.sh.py


#!/bin/bash

test1="2 + 3"

test2="2 - 3"

___________________________________

calculator_test_suit.py


import unittest

from test_calculator import TestCalculatorFunctions

suite = unittest.TestLoader().loadTestsFromTestCase(TestCalculatorFunctions)

unittest.TextTestRunner(verbosity=2).run(suite)

______________________________________________

test_calculator.py


import unittest

import calculator_functions as calc

________________________________________________

test_calculator_pytest.py

#!/use/bin/env python
"""
tests for the calculator module
designed to be run with pytest
"""

import pytest
import calculator_functions as calc

# a very simple test

def test_add():

    assert calc.add(2, 3) == 5

# testing with a variety of parameters:

def test_multiply_ugly():

    """

    the ugly, not very robust way....

    """

    assert calc.multiply(2, 2) == 4

    assert calc.multiply(2, -1) == -2

    assert calc.multiply(-2, -3) == 6

    assert calc.multiply(3, 0) == 0

    assert calc.multiply(0, 3) == 0

param_names = "arg1, arg2, result"

params = [(2, 2, 4),

          (2, -1, -2),

          (-2, -2, 4),

          (3, 0, 0),

          ]

@pytest.mark.parametrize(param_names, params)

def test_multiply(arg1, arg2, result):

    assert calc.multiply(arg1, arg2) == result

Explanation / Answer

HI ,, See below simple one for area of triangle

# Python Program to find the area of triangle

a = 5
b = 6
c = 7

# Uncomment below to take inputs from the user
# a = float(input('Enter first side: '))
# b = float(input('Enter second side: '))
# c = float(input('Enter third side: '))

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)

output

The area of the triangle is 14.70

---------------------------------------

# Python Program to find the L.C.M. of two input number

# define a function
def lcm(x, y):
"""This function takes two
integers and returns the L.C.M."""

# choose the greater number
if x > y:
greater = x
else:
greater = y

while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1

return lcm

# change the values of num1 and num2 for a different result
num1 = 54
num2 = 24

# uncomment the following lines to take input from the user
#num1 = int(input("Enter first number: "))
#num2 = int(input("Enter second number: "))

print("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2))


output


The L.C.M. of 54 and 24 is 216