Answers for "adds the digits in a 2 digit number python"

3

how to sum digits of a number in python

number = 123 # the number you want summed up
sum_of_digits = 0 
for digit in str(number):
  sum_of_digits += int(digit)
  
print(sum_of_digits) # printing the final sum of number
Posted by: Guest on April-25-2020
0

how to format integer to two digit in python

You can achieve this using formatted string
num = 1
number = f"{num:02}"
--------------
output:
"01"
Posted by: Guest on December-12-2021

Code answers related to "adds the digits in a 2 digit number python"

Python Answers by Framework

Browse Popular Code Answers by Language