0

How to take an integer input say 24 and use it to add 2 and 4 = 6 in the next step?

I wish to ask a number say 1234 and I want to add 1 2 3and 4 in the next step.

13th Aug 2020, 4:55 PM
Purnima Tripathi
Purnima Tripathi - avatar
5 ответов
+ 4
Purnima Tripathi , it would be nice if you could show us your attempt in code? thanks!
13th Aug 2020, 5:15 PM
Lothar
Lothar - avatar
+ 2
def getsum(n): s=0 while n>0: s=s+ int(n%10) n= int(n/10) return s The code was as above
13th Aug 2020, 7:09 PM
Purnima Tripathi
Purnima Tripathi - avatar
+ 1
Try it by own first. Simple one.. Mention what trouble you getting in that... Edit: Purnima Tripathi For integer input use casting..... x = int(input())
13th Aug 2020, 5:39 PM
Jayakrishna 🇮🇳
+ 1
Check my code https://code.sololearn.com/cp6nKILK7pfJ/?ref=app I used it here. So the issue is now resolved.
13th Aug 2020, 7:08 PM
Purnima Tripathi
Purnima Tripathi - avatar
+ 1
Purnima Tripathi good code.. Remove line no:3 Why you write 2 times same.. Use looping instead. OK. Nice one..
13th Aug 2020, 7:22 PM
Jayakrishna 🇮🇳