Python Tutorials - Program To Print Sum Of Digits Of Positive Integer Number
ฝัง
- เผยแพร่เมื่อ 6 ก.ค. 2024
- In this Python programming video tutorial we will learn about the program to print the sum of all the digits in entered input.
To write the program we need to follow three steps.
1. Take input
2. get the digit from the number and add them
3. Print the sum
Here we are using simple mathematic operations.
#PythonProgramming #Python
For more free tutorials on computer programming
/ amulsacademy
/ amulsacademy
Thank you @amuls academy for clear explanation it's helps a lot to us to improve programming skills
I went through almost all videos.
Glad to hear that :)
Today I am searching my doughts coming your videos it's really helpful to me i am watching all videos of python
You are very intelligent and can explain in a very simple way
Awesome explanation loved it :)
Excellent
This is the first tym I have seen ur video
Expecting more programs like this
Sure 👍
Please could you upload writing of programs using function. It’s very important
Thanks, well explained.
Why do we use 10 when performing floor and modulo division?
My favourite python channel! Thank you for efforts!
Thank you:)
Thank you so much for help!
I need to compute a column of integers with python. I have some of the code but need the other code.
Is there video for cgi program with xampp apache in python
what about
if we have input as 2
and out put as
24
2+22
Thank you vey much madam....
Mam do a video for sum of digits without loops
Good job keep it up 👍🏻
Tq mam🎉🎉
clear explanation❤❤
Why is it necessary to take result =0 or 1 pls reply. Tommorow is my practical.
Thank you
Thank you so much
THANK YOU SO MUCH
Thank you, you saved my grade
Thanks a lot
Thank you so much! This was really helpful.
Pleasure :)
Such an awesome explanation 🤗
Thank you :)
what if you input a number 5 then the result = 15?
thank you :)
Thank you for helping us out with so well explained and easily understandable manner.👍
Pleasure 😊
Thanks a lot you explain in details so this is the methodology of algorithms
Glad it was helpful!
@@AmulsAcademy mam y cant you use len method on integer when you can use len method in list which can contain integer.
I.e len( list1)
You can use len on it era less and integer number is not an iterable :)
@@AmulsAcademy but you can use it on a list containing integers.
So how is it possible not to use in integers
Thanks a lot Sister. Could you please help me to do this module with function?
Very nice voice ❤️ and nice explaination
Thank you so much for this video..
I need only a single digit sum... what to do?
Good Effort...keep on
Thank you:)
Very good
Mam I am Your True Fan..I am Following Your Every Single Video.Mam I have a request It,s very urgent..For My Campusing purpose i need to learn data struture ..Please Mam Make video series on data structure using python.plz mam plz
Thank you so much:)
Sure i will do:)
I will already uploaded videos on list tuple dictionary sets.
Stack queue will do it soon:)
Best channel I have ever seen. Thank you for existing
Thank you :)
@@AmulsAcademy :)
Sisy.. plz put video for representing grey code...It will be very useful as no one has revealed the video in this topic
Will try 😊
I have a doubt in the programme please help
Str="ABCD"
Str[0:3]
Output- 'ABC'
But why
Str[3] is 'D'
In case of [0:3] and only [3] both are the end values according to [start:stop:step] start and step are optional but in case of [3] why it wont do 3-1 but in [0:3] or [:3] it will do 3-1
Please reply...
Because slicing strings is different from accessing single character.
in slice method end is exclusive that's why str[0:3] is "ABC"
in the case str[3] you are accessing single character from the string using its positve index.
It will give you the character present in that index.
we will use slice when we want to get sub string from the string.
Both are different.
:)
Amuls Academy :)
Both are different str[3] is indexing which starts from 0 and when we use : it slice it excluding last digit which is D
Thankyou
if i give num as 178 in same code i am getting 16 but answer should be 7
how to do?
How to do sum in any base?
good explanation
Thank you 😊
thank you amulya
Welcome :)
Can you upload a video on insertion sort
Sure:)
when i giving num = 1234
the result is 10
i need answer 1
0 + 1
how to add result a;so
Try this:
num = 12345
n = num
while len(str(num))>1:
result=0
for i in str(num):
result = result+int(i)
num=result
print(result)
could you please tell me how to separate a value input= 123 output=1 2 3
I have seen your video its a detailed explanation of python thank you
You can use loop to print value separately 😊
sum of every three integer put one vedio mam
Thank you so much ❤️
Welcome :)
@@AmulsAcademy Mam can u pls help me with these questions...1. Write a program to enter marks obtained by a student in 5 subject. Then find average of marks.
2. Repeat the above program for n students.
3. Write a program to enter a number. Find sum of digits and then find factors of the sum of digits.
Eg if number is 564 then sum is 15 and factors are 1,3,5,15
How will I count no of note from given amount
Pls reply 🥺
Thank a lot....I got clear explanation
How to print this sequence:
Input : 1 2 3 4 5
Output: 3 6 10 15
Thank you :)
can you explain more about the sequence :)
@@AmulsAcademy To print the consecutive sum of numbers in an array
Input : 1,2,3,4,5
Output: 3,6,10,15
@@AmulsAcademy Thanks
can` we do this with while loop???
Yes :)
Amulya mam is the best :)
Thank you :)
-123 I/p lete he to o/p kya hoga ? Aor kese?
Is there a loop ? 🤨
Mam what is the use of )) instead cant we just use ) ??
Where ?
helpful
How to slove only sum of even digit and odd digit ,what type condition use
You can use %2 ==0 and try.
@@AmulsAcademy use but error come
in the above out put you give 1234 then 1+2+3+4 = 10 but i want output in single digit like 1+2+3+4=10 =1+0=1 how to execute it to get single digit output can u help me.
n = int(input("enter the number:"))
while True:
result=0
for i in str(n):
result = result+int(i)
if result>9:
n=result
else:
print("sum in single digit is:",result)
break
:)
@@AmulsAcademy how do do this using functions?
The data is from a file. Yes, I can open and read the file.
def add_num(n):
num = [int(x) for x in str(n)]
result = sum(num)
return result
i fucking love you
Beautiful voice
Tq so much
Welcome 😊
👍👍 .....
Madam plz do more programs on lists
Ok :)
best ever👍🇵🇰❤
Thank you :)
In last line why are u write result...plz tell me.. ...in your last videos you write input value as num
Because we stored our result(sum) in the variable "result" .
:)
Thanku..
Welcome :)
Welcome :)
11:45 find outing😅
Could you please tell me program to get out put as5+6+7=13=1+3=4 mam.
Use a loop, until the length of final result becomes 1, add its digits 😊
MAAM IT WAS A GREAT VEDIO THANKS
My Pleasure :)
Num=int(input("Please Enter the Numbers))
Res=0
For I in str(Num) :
Res=Res+int(Num)
Print (Res)
Without the help of str function do we have any other method
Yes
def reversenum(num):
ans = 0
leng = len(str(num))
for i in range(leng):
a = num % 10
ans = ans + (a * (10 ** (leng - i - 1)))
num = num // 10
return ans
a=11222211
print(reversenum(a))
Ma'am you do explain very nicely and in an understandable and simple way.
Ma'am please can you help me execute this program in python:
A program which repeatedly print for a sentence (string) or for 'q' to quit.
Upon input of a sentence s, print the string produced from s by converting each lower case letter to upper case and each upper case to lower case.
All other characters are left unchanged.
Ma'am I will be really glad if u help me. This is from Sumita Arora book of class 11.
Ma'am please make a video on this or post the full program. Please ma'am ! Please !
You can try this:
while True:
str1 = input("enter the string:")
str2 = str1.swapcase()
print(str2)
n = input("want to quit press q else press any button:")
if n=="q":
break
:)
Thank you very much ma'am !
Congratulation I like u voice so cute🖤
I love u
what if I want to add 10 +12 +13 (basically double or triple digit numbers?)
divide it by 100 or 1000
num=input ("enter the num")
sums=0
for i in num:
sums=sums+int(i)
print(sums)
It is working for me. Is it a efficient or wrong code reply plz
👍😊
Actually this is easier
input 12 13 14 15
output 3 4 5 6
how to implement this mam
Use a loop and you can write the program :)
Get the result large number to single digit
How I can get 6 from 15?
Enter input as 15 :)
please someone help me on my question
100th commend😁😁
Thank you :)
Try:
a=input ("entr no.")
sm=0
for i in range (0, len (a)):
sm=sm+int (a [i])
print (sm)
I need program 123 product is 6
You can modify this program :)
n=input('Enter number: ')
sum=0
for i in n:
sum+=int(i)
print(sum)
How to find no.of letters and numbers for given string
Like this
If user enters irfan123666
Output
Letters =5
Numbers = 6
Try this:
string = input("enter the string:")
numbers = 0
letters = 0
for i in string:
if i.isdigit():
numbers = numbers+1
else:
letters = letters+1
print("letters:",letters)
print("numbers:",numbers)
#Space will be treated as letters.
@@AmulsAcademy thank you ☺️
f=int(input("Number:"))
h=str(f)
summ=0
for i in range(len(h)):
s=summ+int(h[i])
summ=s
print(summ)
why are people giving good replies i didn't even understand a thing
This result can be achieved by recursion
def SumDigit(number):
if number == 0:
return 0
else:
return number%10+SumDigit(number//10)
print(SumDigit(int(input('Enter a positive #: '))))
Thanks mam.
I have don't.
I will give one value "120".
I want print "1+2+3+4+5" or "1*2*3*4*5". like this type how.
You can try this:
Inverse factorial function:
def factorial_cap(num):
n = 1
i = 1
while n < num:
i = i + 1
n = n * i
return i
num = int(input("enter the factorial of any value:"))
n = factorial_cap(num)
print(num,"=",end=" ")
for i in range(n,0,-1):
print(i,end=" ")
if i==1:
break
print("*",end=" ")
:)
def sumofdigit(n):
S=0
for i in str(n):
S+=int(i)
return S
is this chintu from whitehat jr ????
No :)
@@AmulsAcademy i know i was just joking 😂.....by the way your content is very good
code :-
num = int(input("enter the string:-"))
print(sum([ i for i in range(num+1)]))
This doesn't work, please check...
This code is also works:
def sum(num):
sum=0
for i in num:
sum=int (i)+sum
print("the sum of num is",sum)
num=input("please enter a number")
sum(num)
!!!!!!!!!!!!!!6
Finding sum of digits of a number until sum becomes single digit
def singledig(n) :
if n == 0 :
return 0
elif n % 9 == 0 :
return 9
else :
return n % 9
a = int(input("enter number :"))
print(singledig(a))
madam are you speak telugu
No :)
You're in the wrong business, you should be making $50,000k per episode doing voice work lol
R u male or female?
Female :)
Amuls Academy I thought you are a little boy 😅😅. How old are u mam?
I am not little boy, i am a graduate :)
Ohh then u got a very cute voice😃
Thank you :)
Useless
Thank you