Best way to learn Python-Code gladiators2021
LEARN PYTHON CODING
Part-4
pallindrome means we reverse the word or a string we get get same result so it is pallindrome
Q.WAP to print to check given string is Pallindrome or not
"""WAP to print to check given string is Pallindrome or not
pallindrome means we reverse the word or a string we get get same result so it is pallindrome
str=input("Enter a string:")
print(str)
str2=str[-1::-1]
print(str2)
if str2==str:
print("Given is string is Pallindrome.")
else:
print("Given string is Pallindrome.")
Q.Write a Program to print to count alphabets, numbers, spaces, others
"""WAP to print to count alphabets,numbers,spaces,others
"""
str=input("Enter a string:")
print(str)
countalpha,countdigit,countspaces,other=0,0,0,0,
for ch in str:
if (ch>='A' and ch<='Z') or ( ch>='a' and ch<='z'):
countalpha=countalpha+1 # or we write countalph+=1
elif ch>='0' and ch<='9':
countdigit=countdigit+1
elif ch==' ':
countspaces=countspaces+1
else:
other=other+1
print("In a given string there are ",countalpha,"alphabets.")
print("In a given string there are ",countdigit," digits.")
print("In a given string therea are " ,countspaces,"spaces.")
print("In a given string there are ",other,"symbol.")
Q.WAP to print to count vowels in a string
"""WAP to print to count vowels in a string
vowels are a ,u,i, o or A, U,I,O E
"""
ans='y'
while(ans=='y'):
str=input("Enter a string:")
print(str)
countvowel=0
for ch in str:
if ch=='a'or ch=='u' or ch=='e'or ch=='i' or ch=='o':
countvowel=countvowel+1
if ch=='A'or ch=='U'or ch=='E'or ch=='I'or ch=='O':
countvowel=countvowel+1
print("In a given string there aare ;",countvowel,"vowels.")
ans==input("Do you want to execute again the program?(Enter y for yes):")
Q.Write a program to print by interchanging the alphabet small to capital
""" WAP to print to read given character is samall or capital then to interchange character
"""
ch=input("Enter a string:")
if ch.isalpha(): #here ch.isalpha() is a function to check given character is alphabet or not
if ch>='a'and ch<='z':
ch=ord(ch)-32
print("Your alphabet after interchanged:",chr(ch))
else:
ch=ord(ch)+32
print("Your alphabet after interchanged:",chr(ch))
else:
print("Enter only alphabet symbol:")
Output:
Enter a string:g
Your alphabet after interchanged: G
Q.Write a Program to print to count words in a given string
""" WAP to print to count words in a given string
mynameabcd
countword is 1
My name is abcd
countword=4
"""
str=input("Enter a string:")
print(str)
countword=1 # Here we take countword =1 because it start count from where it get first space but our one is left behind it thats why we assume countword=1
for ch in str:
if ch==' ':
countword=countword+1
else:
pass
print("there are ",countword,"words in the string.")
No comments:
If you have any doubt so you can comment me then i will 100% help you ,Through comment Chat