Python Program to Read a Number n and Compute n+nn+nnn














































Python Program to Read a Number n and Compute n+nn+nnn



Problem Statement: Find the value of the sum of n+nn+nn. The user should be allowed to input n as per their discretion

Solution:
Step 1: Take a variable n, and ask the user to input a number that can be dynamically assigned to the variable n
Step 2: Compute the values of nn and nnn by assigning 2*n and 3*n to the variables value_nn and value_nnn respectively
Step 3: Compute the answer that will be printed by taking a sum of all three values
Step 4: Print the final Answer

class ComputeN:

def getn(self):
n = int(input("Please enter a number: "))
nn = 2 * n
nnn = 3 * n
answer = n + m + l
print("The sum of ", n, "+", nn, "+", nnn, "is: ", answer)

Compute = ComputeN()
Compute.getn()


def main():

if __name__ == '__main__':
main()

Output:

/Users/sana2398/Desktop/Sana/CPPSecrets/venv/bin/python "/Users/sana2398/Desktop/Sana/CPPSecrets/Read n and compute n+nn+nnn.py"
Please enter a number:
5
The sum of
5 + 10 + 15 is 30

Process finished
with exit code 0


Comments

  • Pankaj
    1-Jun-2019 05:09:02 PM
    class ComputeN:

    def getn(self):
    n = int(input("Please enter a number: "))
    nn = 2 * n
    nnn = 3 * n
    answer = n + m + l
    print("The sum of ", n, "+", nn, "+", nnn, "is: ", answer)

    def main():
    Compute = ComputeN()
    Compute.getn()

    if __name__ == '__main__':
    main()