Code gladiators-2021 Best way to learn Python level-4


Best way to learn Python-Code gladiators2021



        LEARN PYTHON CODING

Part-4

# Here we will do coding and make program  about string

 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

in this  program we will learn how could we count number of vowels ,number alphabets,spaces and other symbols in the string.If you will enter the string by user so you can count these things by using  the program.

"""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

in this program we will learn how could we make a program to our program again and again until user not say No to stop the program.
In this program we will make program to count a number of vowel in the given string by the user.

"""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.")

         

OUTPUT:

Enter a string:My nameia abcd
My nameia abcd
there are  3 words in the string.


Q.Write a Program  To ask for usename and pcode if username is in pcode then it is not valid code
and pcode matches Trident111  



""""WAP To ask for usename and pcode if username is in pcode then it is not valid code
and pcode matches Trident111  


"""

username=input("Enter your username:")
pcode=input("Enter  a pcode:")
if "username" in pcode and "Trident111" not in pcode:
    
    print("Your code is  not valid.")
else:
    print("Your code is valid.")









Q.Write  a program To count lowercase and upper alphabet and digits and symbol in the string





""""WAP To count lowercase and upper alphabet and digits and symbol in the string


"""
str=input("Enter a string:")
lower=0
upper=0
number=0
symbol=0

for a in str:
    if a.islower():
        lower=lower+1
    elif a.isupper():
        upper+=1
    elif a.isdigit():
        number+=1
    else:
        symbol+=1
print("There are ",lower,"lowercase.")
print("There are",upper,"uppercase.")
print("There are",number,"digits in the string.")
print("There are ",symbol,"Symbol.")

 

   

OUTPUT:





Q.Write a program  To check second string in main string or not




""""WAP To check second string in main string or not


"""
str=input("Enter a string:")
substr=input("Enter a substring:")

if substr in str:
    print("substring in string.")
else:
    print("Substring is not in  string. ")

Q.Write a program  To print string  in decimal number and print decimal part only


""""WAP To print string  in decimal number and print decimal part only
"""
str=input("Enter a string in decimal :")
t=str.partition('.')                  #Here partition() is used to seperate in three parts 
print(t)
print("Given string",str)
print("Part after decimal is:",t[2])           #because index value 0 is integer part nad index value 1 is . and index value of 2 is decimal part




OUTPUT:

>>>Enter a string in decimal :7464.95847
>>>('7464', '.', '95847')
>>>Given string 7464.95847
>>>Part after decimal is: 95847








Code gladiators-2021 Best way to learn Python level-4 Code gladiators-2021 Best way to learn Python level-4 Reviewed by Shubham Prajapati on February 01, 2021 Rating: 5

No comments:

If you have any doubt so you can comment me then i will 100% help you ,Through comment Chat

Powered by Blogger.