Advertisement
plarmi

[while] Дано натуральное число. Определить сумму цифр в нём

Dec 28th, 2024 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.21 KB | None | 0 0
  1. num = int(input("Enter a number: "))
  2.  
  3. summ = 0
  4.  
  5. if num > 0:
  6.     while num != 0:
  7.         summ = summ + num % 10
  8.         num = num // 10
  9.     print(summ)
  10. else:
  11.     print("Число не натуральное!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement