i want to add the following from a list but the result only concatinates

INTELLECTUAL badass :

Sample value of n is 5

    n = input("Enter a No: ")
    n = "{0}+{0}{0}+{0}{0}{0}".format(n)
    n = n.split("+")
    a=n[0] 
    b=n[1]
    c=n[2] 
    n = (a + b + c) 
    print(n)

Expected Result : 615

Ch3steR :

You can use this.

n = input("Enter a No: ")
n = "{0}+{0}{0}+{0}{0}{0}".format(n)
out=sum([int(i) for i in n.split('+')])

if you want only the first three elements to be added then use this.

out_3=sum([int(i) for i in n.split('+')[:4]])

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=11503&siteId=1