InterviewSolution
Saved Bookmarks
| 1. |
Write a program to calculate number of upper case letters and number of lower case letters?Test on String: ''Tutorials POINT'' |
|
Answer» Program is − def string_test(s):a = { ''Lower_Case'':0 , ''Upper_Case'':0} #intiail count of lower and upperfor ch in s: #for loop if(ch.islower()): #if-elif-else condition a[''Lower_Case''] = a[''Lower_Case''] + 1 elif(ch.isupper()): a[''Upper_Case''] = a [''Upper_Case''] + 1 else: passprint(''String in testing is: '',s) #printing the statements.print(''Number of Lower Case characters in String: '',a[''Lower_Case''])print(''Number of Upper Case characters in String: '',a[''Upper_Case''])Output − string_test(''Tutorials POINT'') String in testing is: Tutorials POINT Number of Lower Case characters in String: 8 Number of Upper Case characters in String: 6 We make use of the methods .islower() and .isupper(). We initialise the count for lower and upper. Using if and else condition we calculate total number of lower and upper case characters. |
|