About 55,700 results
Open links in new tab
  1. python - Sum of digits of a number using While - Stack Overflow

    Oct 16, 2014 · How can I make python sum 123 to give 6 using while? def calc_soma(num): ns = str(num) soma = 0 while soma < len(ns): soma = eval(ns[soma]) soma = soma + 1 return soma

  2. Python Program to Find Sum of Digits of a Number - Tutorial …

    In this section, we discuss how to write a Python Program to Find the Sum of Digits of a Number using a While Loop, for loop, Functions, and Recursion. This program allows the user to enter …

  3. Sum the Digits of a Given Number - Python - GeeksforGeeks

    Feb 24, 2025 · Our goal is to calculate the sum of digits for each number in a list in Python. This can be done by iterating through each number, converting it to a string, and summing its digits …

  4. Python Program to Find the Sum of Digits in a Number using while loop

    In this example, You can find the sum of digits of a number that given by user using while loop statement. Python Code: Output: This code prompts the user to enter a number and then …

  5. Sum of Digits of a Number in Python - Python Guides

    Aug 25, 2024 · To calculate the sum of digits of a number in Python using a while loop, you can repeatedly extract the last digit of the number using the modulus operator (% 10) and add it to …

  6. Python:How to make the sum of the values of a while loop store …

    Aug 23, 2012 · def problem1_3(x): my_sum=0 count = 1 while count<=x: my_sum=my_sum+count count = count+1 return my_sum print(my_sum) Lets assume you set …

  7. 5 Best Ways to Find the Sum of Digits in a Number without

    Mar 7, 2024 · Given an input number, for example 123, the desired output for the sum of its digits would be 6, as 1 + 2 + 3 = 6. This article explores five methods to accomplish this in Python …

  8. Python Program to Add Digits of a Number - BeginnersBook

    Jun 9, 2018 · In this tutorial, we will write a simple Python program to add the digits of a number using while loop. For example, if the input number is 1234 then the output would be 1+2+3+4 …

  9. Sum of Digits of a Number in Python - Know Program

    In this post, we will write a program to find the sum of digits of an integer number in Python. We can use the while loop to write the program. We can also develop a Python program to …

  10. Sum of Digits in Python | Easy While Loop Tutorial - YouTube

    💡 Learn How to Sum the Digits of a Number Using Python While Loop!🔢In this quick and easy Python tutorial, you’ll learn how to add all the digits of a numb...

Refresh