0
0

More than 1 year has passed since last update.

paizaラーニング「各桁の和 Python3編」

Posted at

https://paiza.jp/works/mondai/loop_problems2/loop_problems2__digit_sum
私の回答

n = input()
ans = 0
for i in range(len(n)):
    ans += int(n[i])
print(ans)

模範解答

N = int(input())

digit_sum = 0
while N > 0:
    digit_sum += N % 10
    N //= 10

print(digit_sum)

全く違う書き方でした。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0