~1 min read • Updated Oct 4, 2025
Program Overview
This Python program reads a string from the user and counts how many characters it contains.
The input is terminated when the user presses Enter, and the total character count is displayed.
Spaces and punctuation are included in the count.
Python Code:
# Read a string from user
text = input("Enter a string: ")
# Count characters
count = len(text)
# Display result
print("Number of characters:", count)
Sample Output:
Enter a string: Hello, Shahin عزیز دلم
Number of characters: 23
Step-by-Step Explanation:
- The input() function reads the full line until Enter is pressed
- len(text) calculates the total number of characters
- The result is printed using print()
Written & researched by Dr. Shahin Siami