Calculate the Number of Digits and Letters | Python Program

Опубликовано: 22 Октябрь 2024
на канале: Yes I Can Do
186
5

#Calculate_the_Number_of_Digits_and_Letters #pythonlearning #pythoncode #python3 #coder #learntocode #Tutorial




Problem Solution
1. Take a string from the user and store it in a variable.
2. Initialize the two count variables to 0.
3. Use a for loop to traverse through the characters in the string and increment the first count variable each time a digit is encountered and increment the second count variable each time a character is encountered.
4. Print the total count of both the variables.
5. Exit.


Program Explanation
1. User must enter a string and store it in a variable.
2. Both the count variables are initialized to zero.
3. The for loop is used to traverse through the characters in the string.
4. The first count variable is incremented each time a digit is encountered and the second count variable is incremented each time a character is encountered.
5. The total count of digits and characters in the string are printed.

Runtime Test Cases

Case 1:
Enter string:Hello123
The number of digits is:
3
The number of characters is:
8

Case 2:
Enter string:Abc12
The number of digits is:
2
The number of characters is:
5


















python,react,javascript,java,php,ruby,steve jobs,space music,web development,python projects,c programming,c++,hacking,software engineering,Programming,computer science,software engineer,engineering,how to hack,engineer,visual basic,how to code,software developer,coding for beginners,stack overflow,learn coding,programmer,full stack,linux for beginners,#Python3,#Yes_I_Can_Do,Tutorial,PHP,#Session,#Complete_Registration_System,#Login_System,MySQL