Following Python program will count total number of characters in a given string.
Expected Output: If user enters string = Hello Students, output should be
Total Number of Characters in a String = 14
Program Code:
# Python program to count total number of characters in a given String str1 = input("Enter your string: ") count = 0 #initialize counter to 0 for i in str1: count = count + 1 print("Total Number of Characters in a String = ", count)
Output of Program:
Enter your string: Hello Students Total Number of Characters in a String = 14
* * * * *
No comments:
Post a Comment