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

Problem 24: How Many of a Character

A string S is given on the first line, and a single character C is given on the second line. Print, on one line, how many times C appears in S.

For example, if S is banana and C is a, the answer is 3. If it doesn't appear at all, print 0.

Constraints

1 ≤ length of S ≤ 100 (S and C consist only of lowercase English letters)

Input example 1

banana
a

Output example 1

3

Input example 2

hello
l

Output example 2

2

What you'll train

Cover the edge cases

What you get

  • Write the case of zero occurrences
  • Write whether to distinguish uppercase and lowercase
  • Write how to handle a single-character input

How to ask the AI

Tell the AI the condition that if C doesn't appear at all in S, it should output 0. It also helps to clarify, with concrete examples, whether uppercase and lowercase should be distinguished, reducing the chance of misunderstanding.

If you ask vaguelyIf the case where the count is 0 isn't considered, the AI may write code that returns an error or an empty string.

あなたのコード

実行しました

プレビュー

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

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

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