[go: up one dir, main page]

0% found this document useful (0 votes)
4 views1 page

String

The document contains four Python code snippets that perform different string operations. The first counts vowels and consonants, the second counts lowercase, uppercase, digits, whitespace, and special characters, the third reverses a string, and the fourth checks if a string is a palindrome. Each snippet prompts the user for input and prints the results accordingly.

Uploaded by

Ankita Biswas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

String

The document contains four Python code snippets that perform different string operations. The first counts vowels and consonants, the second counts lowercase, uppercase, digits, whitespace, and special characters, the third reverses a string, and the fourth checks if a string is a palindrome. Each snippet prompts the user for input and prints the results accordingly.

Uploaded by

Ankita Biswas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

1) str = input("Enter a string: ")

v = ['a','e','i','o','u']
str1 = str.lower()
vc=cc=0
for i in str1:
if i in v:
vc += 1
else:
cc += 1
print("Vowel count: ",vc)
2) str = input("Enter a string: ")
lc=uc=dc=wc=sc=0
for i in str:
if i.islower():
lc += 1
elif i.isupper():
uc += 1
elif i.isdigit():
dc += 1
elif i.isspace():
wc += 1
else:
sc += 1
print("Lowercase count: ",lc)
print("Uppercase count: ",uc)
print("Digit count: ",dc)
print("Whitespace count: ",wc)
4) str = input("Enter a string: ")
rstr = str[::-1]
print(rstr)
7) str = input("Enter a string: ")
rstr = str[::-1]
if str == rstr:
print("Palindrome string")
else:
print("Not a palindrome string")

You might also like