Menu Bar

Horizontal Scrollable Menu

ads

Search This Blog

Python | Addition of total number by providing user input

Addition of total user input number in Python 

way--1 user will enter the value in string but we are converting each string into integer and then adding all
num=input("enter digit to sum it: ")
total=int(num[0])+int(num[1])+int(num[2])+int(num[3])
print("total sum is:",total)

Addition of total number 

way--2 here also user will enter string value as input then in while loop find length of input and then converting input into integer then performing addition operation 
example
number = input("enter number:") totals=0
i=0
while i < len(number):
     totals+=int(number[i])
     i+=1
print(totals)

No comments:

ads3