CodeDrill
day_streak: --
← 問題一覧に戻る
Python ・ Standard I/O

Problem 34: Sum of the Digits

An integer N is given on a single line from standard input. Output, on one line, the sum of the digits of N.

For example, if N is 123, then 1 + 2 + 3 = 6, so output 6.

Constraints

1 ≤ N ≤ 1000000000

Input example 1

123

Output example 1

6

Input example 2

9

Output example 2

9

What you'll train

Specify the input

What you get

  • Show how to break a number into digits
  • Specify the type of the input
  • Check boundary values

How to ask the AI

Tell the AI that N is given as an integer and needs to be broken down into its digits before summing them. It's also reassuring to confirm that the program works correctly even when N has only one digit, or when it has many digits.

If you ask vaguelyThe AI may confuse extracting digits from the integer directly with converting it to a string, resulting in an implementation where the digit-splitting method is left ambiguous.

あなたのコード

実行しました

プレビュー

AIレビュー(プロンプト練習)

コードはChatGPTやClaudeに出させたものを貼って構いません。
ここでの本番は「次にAIへ出す指示」です。評価軸は1つだけ見て、弱点・指示の穴・改善例を返します。
テストに落ちていてもレビューできます。落ちた理由と、指示に足りなかった情報を結びつけます。

先にコードを実行し、テストを1つ以上通してください。