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.
5 ответов
+ 4
Purnima Tripathi , it would be nice if you could show us your attempt in code? thanks!
+ 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
+ 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())
+ 1
Check my code https://code.sololearn.com/cp6nKILK7pfJ/?ref=app
I used it here. So the issue is now resolved.
+ 1
Purnima Tripathi
good code..
Remove line no:3
Why you write 2 times same.. Use looping instead.
OK. Nice one..