Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
Here,
The given program is to Read a Number n and Print the Natural Numbers Summation Pattern
I've made a method Which will take n as argument and print the pattern
The Pattern For Number n is
1 = 1
1 + 2 = 3 //1<+2>=
1 + 2 + 3 = 6 //1+2<+3>=
1 + 2 + 3 + 4 = 10 //1+2+3<+4>=
...
...
...
1 + 2 + 3 + 4 + .... + n = <sum of n Natural Numbers>
Here,
Every Pattern is repeating the old pattern and adding its own number so we will store the last pattern in some variable and print the pattern with number
Steps are Given below
1 . Read Number n
2 . call function to print the pattern
THE CODE:
__auth__='Jaymeet Mehta'
defprint_pattern(n): #First Check If number is natural or not if n<1: print("Number is not Natural") return summ=0 last_pattern="1" #LAST_PATTERN TO STORE PREVIOUS OUTPUT #BASIC ADDITION OF 1+2+3+4+5+.....+n for i in range(1,n+1): #For First Line summ+=i if i==1: last_pattern=str(i) else: last_pattern += " + "+str(i) print(last_pattern,"=", summ) number=int(input("Enter Number till which You Want the pattern:")) print_pattern(number)
Comments