You are on page 1of 5

1.Write python program to count vowel in a word entered by user?

CODES:-

# Python Program to Count Vowels and Consonants in a String

str1 = input("Please Enter Your Own String : ")


vowels = 0
consonants = 0

for i in str1:
if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'
or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
vowels = vowels + 1
else:
consonants = consonants + 1

print("Total Number of Vowels in this String = ", vowels)


print("Total Number of Consonants in this String = ", consonants)

RESULTS:-
Please Enter Your Own String : Python Tutorial
Total Number of Vowels in this String =5
Total Number of Consonants in this String =10
2.Write python program to check whether a string is palindrome or not?
CODES:
# Python Program to Check a Given String is Palindrome or Not

string = input("Please enter your own String : ")

if(string == string[:: - 1]):


print("This is a Palindrome String")
 else:
 print("This is Not a Palindrome String")

RESULTS:
Please enter your own String : wow
This is a Palindrome String

3. write python program to remove vowels from string?


CODES:
string = input("Enter any string: ")
if string == 'x':
exit();
else:
newstr = string;
print("\nRemoving vowels from the given string");
vowels = ('a', 'e', 'i', 'o', 'u');
for x in string.lower():
if x in vowels:
newstr = newstr.replace(x,"");
print("New string after successfully removed all the vowels:");
print(newstr);
RESULTS:
Enter any string: atul
Removing vowels from the given string
New string after successfully removed all the vowels:
tl
4.Write the program that takes a sentence as an input from the user where
each word is separated by space and replaces each blank with hypen then
print the modified sentence?
CODES:
a = input("Please Enter Your Own String : ")
ns=a.replace(" ","")

j="-"
print (j.join(ns))

RESULTS:
Please Enter Your Own String : ATUL IS FOODIE
A-T-U-L-I-S-F-O-O-D-I-E
>
5.
CODE:
line=input("Enter a line:")
w=line.split()
count=0
print(w)
for i in w:
count=count+1

lower_count=0
upper_count=0
digit_count=0
alpha_count=0

for i in line:
if i.islower():
lower_count=lower_count+1
elif i.isupper():
upper_count=upper_count+1
elif i.isdigit():
digit_count=digit_count+1
for i in line:
if i.isalpha():
alpha_count=alpha_count+1
print("Number of uppercase:", upper_count)
print("Number of lowercase:",lower_count)
print("Number of alphabet:",alpha_count)
print("Number of digitcount:",digit_count)
print("Number of word:",count)

RESULTS:
Enter a line:Atul is good boy 8
['Atul', 'is', 'good', 'boy', '8']
Number of uppercase: 1
Number of lowercase: 12
Number of alphabet: 13
Number of digitcount: 1
Number of word: 5
>
RESULTS:

You might also like