Question

Complete this by first working these problems on paper, then put them into pep8 and verify...

Complete this by first working these problems on paper, then put them into pep8 and verify they work correctly. Upload the pep0 programs only

  1. Input 3 decimal numbers (integers) . Add them together and output the result. Verify your solution works for positive numbers, and negative numbers.
  2. Input two decimal numbers and then subtract the second from the first. Verify your solution works if the result is positive or negative.
  3. Input one integer using decimal input trap and multiply it by 4. Output the result.
  4. Similar to #3, but divide the integer by 16. Output the result.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Since PEP8 are some conventional rules for python code.

So first install pylint for testing the python code for PEP 8.

Following is the command for installing pylint on ubunto system :

pip install pylint

then run the code in following way to test PEP 8:

python3 -m pylint demo.py

Below is the code for mentioned problem statement written in python3 :

"""
This program consists of addition, subtraction ,multiplication and dividion methods.
"""

def add_3_numbers(list_add):
    """
    This function will do the sum of three numbers
    :rtype: decimal
    """
    sum_all = 0.0
    for item in list_add:
        sum_all = sum_all + item

    return sum_all

def sub_2_numbers(list_sub):
    """
    This function will do the subtraction of two numbers
    :rtype: decimal
    """
    return list_sub[0] - list_sub[1]

if __name__ == "__main__":
    ADDLIST = []
    SUBLIST = []
    print("Please enter 3 numbers for addition : ")
    for x in range(3):
        number = float(input("Enter " + str(x + 1) + " number : "))
        ADDLIST.append(number)
    SUMOFNUMBERS = add_3_numbers(ADDLIST)
    print("Sum of entered numbers : ", SUMOFNUMBERS)

    print("\nPlease enter 2 numbers for subtraction : ")
    for y in range(2):
        number = float(input("Enter " + str(y + 1) + " number : "))
        SUBLIST.append(number)
    SUBNUMBERS = sub_2_numbers(SUBLIST)
    print("Subtraction of entered numbers : ", SUBNUMBERS)

    MULNUMBER = float(input("\nEnter number for multiplication : "))
    print("Multiplication result : ", 4*MULNUMBER)

    DIVNUMBER = float(input("\nEnter number for divide : "))
    print("Division result : ", DIVNUMBER/16)

output:

Please enter 3 numbers for addition :
Enter 1 number : 32134
Enter 2 number : 2342134
Enter 3 number : 3525231
Sum of entered numbers : 5899499.0

Please enter 2 numbers for subtraction :
Enter 1 number : 5325231
Enter 2 number : 3215123
Subtraction of entered numbers : 2110108.0

Enter number for multiplication : 251
Multiplication result : 1004.0

Enter number for divide : 2135
Division result : 133.4375

Process finished with exit code 0

screen shot code before scan by pylint:

screenshot of pylint scan for above code:

After this modifying the code suggested by pylint:

Final pylint report with 0 error or warning : with 10/10 rating : Your code has been rated at 10.00/10 (previous run: 8.46/10, +1.54)

Add a comment
Know the answer?
Add Answer to:
Complete this by first working these problems on paper, then put them into pep8 and verify...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...

    SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){    int num1,num2;    cout << "Enter two numbers "<< endl;    cout << "First :";    cin >> num1;    cout << "Second :";    cin >>num2;    int result=num1+num2;    cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;   ...

  • Assume we are using 6-bit long 2’s complement integers and want to multiply 0x33 by 0x16....

    Assume we are using 6-bit long 2’s complement integers and want to multiply 0x33 by 0x16. Treating the first as the multiplier and the second as the multiplicand, show the steps used to multiply these two numbers together using the algorithm (the one which used one register for both the multiplier and the product). If either of these numbers represent a negative value, convert them to their positive version before multiplying, then negate your answer (if necessary). Give your answer...

  • DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to...

    DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to solve the problem using short methods that work together to solve the operations of add, subtract multiply and divide.   A constructor can call a method called setSignAndRemoveItIfItIsThere(). It receives the string that was sent to the constructor and sets a boolean variable positive to true or false and then returns a string without the sign that can then be processed by the constructor to...

  • public class Rational { // PUT PRIVATE DATA FIELDS HERE /** * The default constructor for...

    public class Rational { // PUT PRIVATE DATA FIELDS HERE /** * The default constructor for objects of class Rational. Creates the rational number 1. */ public Rational() { // ADD CODE TO THE CONSTRUCTOR } /** * The alternate constructor for objects of class Rational. Creates a rational number equivalent to n/d. * @param n The numerator of the rational number. * @param d The denominator of the rational number. */ public Rational(int n, int d) { // ADD...

  • Hello! I'm looking for help with this assignment. Complete a program in pseudocode and Python that...

    Hello! I'm looking for help with this assignment. Complete a program in pseudocode and Python that performs the following tasks. Open the file called M4Lab1ii.py linked below these instructions in your M4 Content module in IDLE. Save as M4Lab1ii.py. Replace ii with your initials. [example for someone with the initials cc: M4Lab1cc.py] Complete Steps 1-7 as requested within the code’s comments. Run your program and test all four calculations, then exit the program. Save your program as M4Lab1ii.py using your...

  • Create a simple calculator. Your interface should contain two input boxes in which the user can...

    Create a simple calculator. Your interface should contain two input boxes in which the user can put two numbers. There should be four buttons: add, subtract, multiply, and divide. When the user inputs two number and clicks on an operation button, the result should be displayed in the label. Can some please help my code that i came up with just displays a pop box with no words or nothing! I'm not the best at coding. Any tips or advice...

  • In Assembly Language Please display results and write assembler code in (gcd.s) The Euclidean algorithm is...

    In Assembly Language Please display results and write assembler code in (gcd.s) The Euclidean algorithm is a way to find the greatest common divisor of two positive integers, a and b. First let me show the computations for a=210 and b=45. Divide 210 by 45, and get the result 4 with remainder 30, so 210=4·45+30. Divide 45 by 30, and get the result 1 with remainder 15, so 45=1·30+15. Divide 30 by 15, and get the result 2 with remainder...

  • Write a program that computes the Fibonacci number for some input integer. (See segments 7.37 –...

    Write a program that computes the Fibonacci number for some input integer. (See segments 7.37 – 7.41 in your book for some info on the Fibonacci sequence or you can look it up on the Internet). The sequence is defined as the first two elements are each 1, after that each element in the sequence is the sum of the previous two elements. The first few numbers of the sequence are 1,1,2,3,5,8,13,21,34,55,… Your assignment is to write a program with...

  • the question just that. here is what i have done, put something wrong with it Week...

    the question just that. here is what i have done, put something wrong with it Week 5- Counts using While or Do-While Loop Write a program that asks the user to input 6 integer numbers, then the program counts the number of negative numbers, the number of positive numbers and counts the number of zeros. Use 'while' loop or 'Do-While loop in your program. Make sure to include comments in the program. Example, if the input numbers are: -23 Then,...

  • C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers...

    C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers using Euclid’s algorithm (also known as the Euclidean algorithm). Write a main () function that requests two integers from the user, calls your function to compute the GCD, and outputs the return value of the function (all user input and output should be done in main ()). In particular, you will find this pseudocode for calculating the GCD, which should be useful to you:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT