write a program whose input is a string which contains a character and a phrase, and whose output indicates…

write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. the output should include the input character and use the plural form, ns, if the number of times the characters appears is not exactly 1.\n\nex: if the input is:\nn monday\nthe output is:\n1 n\n\nex: if the input is:\nz today is monday\nthe output is:\n0 zs\n\nex: if the input is:\nn its a sunny day\nthe output is:\n2 ns\n\ncase matters. n is different than n.\n\nex: if the input is:\nn nobody\nthe output is:\n0 ns

write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. the output should include the input character and use the plural form, ns, if the number of times the characters appears is not exactly 1.\n\nex: if the input is:\nn monday\nthe output is:\n1 n\n\nex: if the input is:\nz today is monday\nthe output is:\n0 zs\n\nex: if the input is:\nn its a sunny day\nthe output is:\n2 ns\n\ncase matters. n is different than n.\n\nex: if the input is:\nn nobody\nthe output is:\n0 ns

Answer

Explanation:

Step1: Read the input string

Read the entire line of input and split it into the target character and the phrase.

Step2: Count character occurrences

Iterate through the phrase and count how many times the target character appears, maintaining case sensitivity.

Step3: Determine output formatting

Check if the count is exactly 1 to use the singular form; otherwise, append "'s" to the character for the plural form.

Step4: Print the result

Output the count followed by the formatted character string.

Answer:

user_input = input().split()
target_char = user_input[0]
phrase = " ".join(user_input[1:])

count = 0
for char in phrase:
    if char == target_char:
        count += 1

if count == 1:
    print(f"{count} {target_char}")
else:
    print(f"{count} {target_char}'s")