addition of number using for loop and providing user input data in python


addition of number using for loop and providing user input data in python

Addition using for loop

num=int(input("enter number:"))
total=0
for i in range(1,num+1):
total+=i
i+=1
print("total sum is:",total)

Sum of all input number in Python

n=input("enter number: ")

total=0
for i in range(len(n)):
total+=int(n[i])
i+=1

print(total) 

InPut:
enter number : 12345
OutPut:
15

Simple way for Addition by using def in Python

 
def add():
return "sum of these two number is:",
11+99
 
print(add())
addition of number using for loop and providing user input data in python

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories