PracticeStrings

Count Characters in a File Record

BeginnerStringstraversalaccumulationcounting Time not estimated Not started

Context

A file-ingestion tool receives one record as a string before parsing it. The record may contain letters, digits, punctuation, spaces, or other whitespace. Determine how many characters the tool received so it can track record sizes consistently.

Problem

Write a function that returns the number of characters in the supplied file record. Start a counter at zero and account for each character exactly once while traversing the record. Every character is ordinary content: spaces, tabs, and other whitespace must be included rather than removed or skipped. An empty record has a count of zero.

Examples

Example 1
Input: record = "Hello"
Output: 5
Explanation: For the record `Hello`, the executed function returns 5, and its final counter value is 5.
Example 2
Input: record = "Line one\tLine two"
Output: 17
Explanation: For the record `Line one\tLine two`, the executed function returns 17; the tab is included in that count.
Example 3
Input: record = ""
Output: 0
Explanation: For the empty record, the executed function returns 0, with a final counter value of 0.

Constraints

  • 0 <= len(record) <= 5000
  • Types: record is str; result is int

Function signature

def count_record_characters(record: str) -> int
record str
The complete file record whose characters must be counted.
returns int
The total number of characters in record, including whitespace.

Adapted from MBPP problem task_813 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Notes

  • The input is already provided as one string; no parsing or delimiter handling is needed.
Approved · t3-abs_213_v314 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1