Page 377 - Computer Science Class 11 Without Functions
P. 377
countLowerCase += 1
else:
countUpperCase += 1
print("The number of vowels are : ", countVowels)
print("The number of consonants are : ", countConsonants)
print("The number of uppercase characters are : ", countUpperCase)
print("The number of lowercase characters are : ", countLowerCase)
Program 12
Write a program that accepts a string as input from the user and checks whether the string is a palindrome or not.
Ans. '''
Objective: To check whether a string is a palindrome
Input: string
Output: result whether it is palindrome or not
'''
string = input("Enter a string: ")
reverseStr = string[::-1]
if reverseStr == string:
print("Given string is a palindrome.")
else:
print("Given string is not a palindrome.")
Program 13
Write a program that takes a user-provided string as input and then generates a new string where the case (uppercase
to lowercase and vice versa) of each character in the original input is reversed, and finally, print the resulting string.
Ans. '''
Objective: To swap the case of the characters of the string
Input: string
Output: string with case swapped
'''
string = input("Enter a string: ")
newString = ''
for char in string:
if char.isalpha():
if char.islower():
newString += char.upper()
else:
newString += char.lower()
else:
newString += char
print("The string after reversing the Case is : ", newString)
Practical 375

