String Concept in Python, String Tutorials in Python, String important interview question on Python

84



The string is a collection of char, it will arrange multiple char using sequence. The string char index will be to start from 0 to length-1.
The string will be declared using  ' '" "  and  """
a= 'welcome'   #single line string
a= "welcome" #single line
a= """ welcome in scs """   #multiple line with proper syntax format

WAP to count total vowel and consonant in String?
s= 'welcome'    #['w','e','l','c','o','m','e']
c=0
d=0
for i in range(0,len(s)):
    if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
        c=c+1
    else:
        d=d+1
print("vowel",c,"consonant",d)     
Another 
another way to create this program:-
s = input("Enter word")
v=0
c=0
for i in range(0,len(s)):
    if s[i] in ('a','e','i','o','u'):
        v=v+1
    else:
        c=c+1
print("Total vowel is ",v, "Consonent is ",c)        
another way to create this program:-
s = input("Enter word")
v=0
c=0
for ch in s:
    if ch in ('a','e','i','o','u'):
        v=v+1
    else:
        c=c+1
print("Total vowel is ",v, "Consonent is ",c)  
......................................................................
MOST OF THE STRING PROGRAM WILL BE RELATED TO ASCII CODE HENCE PYTHON PROVIDE TWO DIFFERENT METHOD TO PERFORM OPERATION FROM
ASCII TO CHAR AND CHAR TO ASCII
1)  ord():-   this function is used to return the ascii code of particuar char
                  print(ord('a'))  #97   #char to ascii'
2)  chr():-  this function is used to return jhar from ascii code 
                    print(chr(65))   #A    #ascii to char
WAP to find max char in String?
s= 'ramesh'
m = s[0]
for i in range(1,len(s)):
   if m<s[i]:   #s<h
       m=s[i]
print(m) 
ASSIGNMENT:-
1)WAP to reverse string where vowel will be in the same position?
for example  Ramesh          hasemr
Solution:-
s="ramesh"
s1=""
s1 += s[5]
s1 += s[1]
s1 += s[4]
s1 += s[3]
s1 += s[2]
s1 += s[0]
print(s1)
2) WAP to check palindrome in String?
example  madam, naman
Solution
s="madam"
c = len(s)-1
flag=True
for i in range(0,len(s)//2):
    if s[i]!=s[c-i]:
        flag=False
        break
 if flag:
    print("pallindrom")
else:
    print("np")
Another way to check the program of a palindrome:-
s = "gggggg"
for i in range(0,len(s)//2):
    if s[i]!= s[(len(s)-1-i)]:
        print("Not Pallindrom")
        break
else:
    print("Pallindrom")
3) WAP to convert a string from upper case to lower case and lower case to upper case?
Solution:-
s="MADAM"
s1=""
for i in range(0,len(s)):
   s1+=chr(ord(s[i])+32)
print(s1)
Program to convert String in Opposite case?
s = "Hello"
s1 = ""
for d in s:
    if ord(d)>=65 and ord(d)<=91:
      s1 = s1 + chr(ord(d)+32)
    else:
      s1 = s1 + chr(ord(d)-32)
print(s1)   
4) WAP to replace the string char from the next consecutive String char  (if char will be z then replace by a)?
   Manish  o.p  nbojti 
5) WAP to extract numeric, alphabets, and special char in separate string in any String?
s = "abcd123@7$f"
abcdf
123
@$
6)  WAP to display a number of repeated char in String?
hello     h 1 e 1 l 2 o 1
Solution of this program:-
s = "mangalam"
for i in range(0,len(s)):
    c=0
        for k in range(0,i):
        if s[i]==s[k]:
            break
    else:    
     for j in range(i,len(s)):
        if s[i]==s[j]:
            c=c+1
     else:
        print(s[i],c)
7)  WAP to validate emaild?  (@, ., the position of @ should be lesser of last dot position)
8)  WAP to display a strength of password that password is weak, medium, and Strong according to predefined cases?
Strong (at least 3 special char, non-consecutive, not belonging with first name and Lastname, one upper case char and numeric is mandatory, length minimum 6)
Medium (at least 2 special char, non-consecutive, length minimum 6)
Tags

Post a Comment

84Comments

POST Answer of Questions and ASK to Doubt

  1. Assignment1
    #wap to replace string to next consecutive string
    str=input("enter string")
    for i in range (0,len(str)):

    x=ord(str[i])
    if x>=65 and x<=90:
    x=x+1
    print(chr(x))
    else:
    x>=97 and x<=122
    x=x+1
    print(chr(x))

    ReplyDelete
  2. Assignment2
    #wap to convert a string from upper case to lower case and vice-versa
    string=input("enter string")
    for i in range(0,len(string)):
    s=ord(string[i])
    if s>=65 and s<=90:
    s=s+32
    s1=chr(s)
    print(s1,end='')

    else:

    s=s-32
    s1=chr(s)
    print(s1,end='')

    ReplyDelete
  3. Assignment 3-
    #WAP to extract numeric, alphabets, and special char in separate string in any String?
    str=input("enter any string")
    s1=''
    s2=''
    s3=''
    for i in range(0,len(str)):
    s=ord(str[i])
    if s>=48 and s<=57:
    s1=chr(s)
    print("enter string is numeric",s)
    elif(s>=65 and s<=90) or (s>=97 and s<=122):
    s2=chr(s)
    print("alphabet string",s)
    elif(s>=32 and s<=47) or (s>=58 and s<=64) or (s>=123 and s<=126):
    s3=chr(s)
    print("special charcter is",s3)

    ReplyDelete
  4. #predefine method of string
    1)capatlize()-Converts the first character to upper case
    implement-
    s1 = "hello, and hi"

    x = s1.capitalize()

    print (x)
    2)casefold()-Converts string into lower case
    implement-
    s2 = " Welcome To My World"

    x = s2.casefold()

    print(x)
    3)centre()-Returns a centered string
    implement-
    s3 = "banana"

    x = s3.center(20)

    print(x)
    4)count()-Returns the number of times a specified value occurs in a string
    implement-
    s4 = "I love mango,mango is yellow color "

    x = s4.count("mango")

    print(x)
    5)Upper()-Converts a string into upper case
    implement-
    s5 = "Hello my friends"

    x = s5.upper()

    print(x)
    6) translate()- method returns a string where some specified characters are replaced with the character described in a dictionary
    mydict = {65: 70};
    s6 = "Hello hi!";
    print(s6.translate(mydict));

    7)strip()-The strip() method removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove)

    implement-
    s7 = " company "

    x = s7.strip()

    print("mnc", x, "TCS")
    8)isnumeric()- isnumeric() method returns True if all the characters are numeric (0-9), otherwise False.
    implement-
    s8 = "12345"

    x = s8.isnumeric()

    print(x)
    9) format()- method formats the specified value(s) and insert them inside the string's placeholder.
    example-
    Insert the price inside the placeholder, the price should be in fixed point, two-decimal format:

    implement-

    s9 = "For only {price:.2f} dollars!"
    print(s9.format(price = 49))
    10) islower()- method returns True if all the characters are in lower case, otherwise False.

    Numbers, symbols and spaces are not checked, only alphabet characters.
    Check if all the characters in the text are in lower case:

    s10 = "hello world!"

    x = s10.islower()

    print(x)







































    #predefine method of string
    1)capatlize()-Converts the first character to upper case
    implement-
    s1 = "hello, and hi"

    x = s1.capitalize()

    print (x)
    2)casefold()-Converts string into lower case
    implement-
    s2 = " Welcome To My World"

    x = s2.casefold()

    print(x)
    3)centre()-Returns a centered string
    implement-
    s3 = "banana"

    x = s3.center(20)

    print(x)
    4)count()-Returns the number of times a specified value occurs in a string
    implement-
    s4 = "I love mango,mango is yellow color "

    x = s4.count("mango")

    print(x)
    5)Upper()-Converts a string into upper case
    implement-
    s5 = "Hello my friends"

    x = s5.upper()

    print(x)
    6) translate()- method returns a string where some specified characters are replaced with the character described in a dictionary
    mydict = {65: 70};
    s6 = "Hello hi!";
    print(s6.translate(mydict));

    7)strip()-The strip() method removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove)

    implement-
    s7 = " company "

    x = s7.strip()

    print("mnc", x, "TCS")
    8)isnumeric()- isnumeric() method returns True if all the characters are numeric (0-9), otherwise False.
    implement-
    s8 = "12345"

    x = s8.isnumeric()

    print(x)
    9) format()- method formats the specified value(s) and insert them inside the string's placeholder.
    example-
    Insert the price inside the placeholder, the price should be in fixed point, two-decimal format:

    implement-

    s9 = "For only {price:.2f} dollars!"
    print(s9.format(price = 49))
    10) islower()- method returns True if all the characters are in lower case, otherwise False.

    Numbers, symbols and spaces are not checked, only alphabet characters.
    Check if all the characters in the text are in lower case:

    s10 = "hello world!"

    x = s10.islower()

    print(x)







































    ReplyDelete
  5. Program to count vowels and consonant in a string-->>

    p="shiva concept solution"
    c=0
    v=0
    for i in range(0,len(p)):
    if p[i]=="a" or p[i]=="e" or p[i]=="i" or p[i]=="o" or p[i]=="u":
    v=v+1
    else:
    c=c+1
    print("total consonants=",c,"total vowels=",v)

    ReplyDelete
  6. Program to check palindrome in string-->>

    1st method-->>

    s="nama"
    c=len(s)-1
    flag=True
    for i in range(0,len(s)//2):
    if s[i]!=s[c-i]:
    flag=False
    break
    if flag:
    print("palindrome")
    else:
    print("not a palindrome")


    2nd method-->>
    x = "refer"
    w=""
    for i in x:
    w=i+w
    if (x==w):
    print ("it is a palindrome")
    else:
    print("it is not a palindrome")

    ReplyDelete
  7. Program to convert string from upper case to lower case and lower case to upper case-->>

    s="SUBSERVIENT"
    s1=""
    for i in range(0,len(s)):
    s1+=chr(ord(s[i])+32)
    print(s1)

    ReplyDelete
  8. # PYTHON( 6 To 7 PM BATCH)

    #CODE to Find Palindrome String

    a=input("Enter The String :\t")
    b=a[len(a)::-1]
    if a== b:
    print(" Palindrome String")
    else:
    print("Not a Palindrome String")

    ReplyDelete
  9. #To check pallindrome
    s = "poppop"
    c= len(s)-1
    flag=True

    for i in range(0, len(s)//2):
    if s[i]!=s[c-i]:
    flag = False
    if flag:
    print(s,"Is Pallindrome")
    else:
    print(s,"Is Not Pallindrome")

    ReplyDelete
  10. # Upper case_lower case
    s = "HELLO"
    c=''

    for i in range(0,len(s)):
    c+= chr(ord(s[i])+32)
    print(c)

    ReplyDelete
  11. # String in reverse form
    s= "parag"

    for i in range(0,len(s)):
    c=s[i]
    b= chr(97+(122-ord(c)))
    print(b,end='')

    ReplyDelete
  12. #WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)?
    a = "zebra"

    for i in range(0,len(a)):
    if a[i]=="z":
    print("a",end='')
    else:
    b= chr(ord(a[i])+1)
    print(b,end='')

    ReplyDelete
  13. #WAP to extract numeric, alphabets, and special char in separate string in any String?
    x= "My name is Arun, arun@gmail.com, c.s branch, my percentage is 98%."
    num=''
    sc=''
    st=''

    for i in range(0,len(x)):
    if x[i]=="1" or x[i]=="2" or x[i]=="3" or x[i]=="4" or x[i]=="5" or x[i]=="6" or x[i]=="7" or x[i]=="8" or x[i]=="9" or x[i]=="0":
    num = num + str(x[i])

    if x[i]=="!" or x[i]=="@" or x[i]=="#" or x[i]=="$" or x[i]=="%" or x[i]=="^" or x[i]=="&" or x[i]=="*" or x[i]=="(" or x[i]==")" or x[i]=="." or x[i]==",":
    sc = sc+str(x[i])

    else:
    if x[i] not in(num or sc):
    st =st+ x[i]

    print(num)
    print(sc)
    print(st)

    ReplyDelete
  14. Program to display repeated char in String
    s = "welcomeo"
    count=[]
    for i in range(0,len(s)):

    c=1
    for j in range(i+1,len(s)):
    if s[i]==s[j] and s[i] not in count:
    c=c+1

    if s[i] not in count:
    count.append(s[i])
    print(s[i],c)



    print(count)

    ReplyDelete
  15. # Python( 6 To 7 PM BATCH)

    # CODE for Reverse String Where Vowel will be in the Same Position.

    s="ramesh"
    s1="";

    for i in range(len(s)-1,-1,-1):

    if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
    s1+=s[i]
    else:
    s1=s1+s[i]

    print(s1)

    ReplyDelete


  16. # PYTHON ( 6 To 7 PM BATCH)
    # CODE to replace the string char from the next consecutive String char.

    s=str(input("Enter Any Name :-\t"))
    s1 = ''
    for i in s:

    if i=="Z":
    s1 = s1 +"A"
    else:

    s1 =s1+chr(ord(i)+1)

    print(s1.upper())

    ReplyDelete

  17. # PYTHON ( 6 To 7 Pm BATCH)
    # Program to Extract Numeric, Alphabets And Special Character from String.

    i = input("Please Enter Your Own Character : ")


    for ch in i:
    if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
    print("The Given Character ", ch, "is an Alphabet")
    elif(ch >= '0' and ch <= '9'):
    print("The Given Character ", ch, "is a Digit")
    else:
    print("The Given Character ", ch, "is a Special Character")

    ReplyDelete

  18. # PYTHON ( 6 To 7 PM BATCH)
    # Program to Display a Number of Repeated Char in String.

    s = "ROHIT-KUMAR-PYTHON-CLASS"

    for i in s:

    a= s.count(i)

    if a==1:
    print(i,"--",a)
    a = 0

    if a>1:
    print(i,"--",a)
    s= s.replace(i,'')
    a = 0

    ReplyDelete
  19. #Akash patel
    #wap to replace string to next consecutive string:-
    str=input("enter string")
    for i in range (0,len(str)):

    x=ord(str[i])
    if x>=65 and x<=90:
    x=x+1
    print(chr(x))
    else:
    x>=97 and x<=122
    x=x+1
    print(chr(x))

    ReplyDelete
  20. #Akash patel
    #wap to convert a string from upper case to lower case and loer to uper
    string=input("enter string")
    for i in range(0,len(string)):
    s=ord(string[i])
    if s>=65 and s<=90:
    s=s+32
    s1=chr(s)
    print(s1,end='')
    else:
    s=s-32
    s1=chr(s)
    print(s1,end='')

    ReplyDelete
  21. #Akash patel
    #WAP to extract numeric, alphabets, and special char in separate string in any String?
    str=input("enter any string")
    s1=''
    s2=''
    s3=''
    for i in range(0,len(str)):
    s=ord(str[i])
    if s>=48 and s<=57:
    s1=chr(s)
    print("enter string is numeric",s1)
    elif(s>=65 and s<=90) or (s>=97 and s<=122):
    s2=chr(s)
    print("alphabet string",s2)
    elif(s>=32 and s<=47) or (s>=58 and s<=64) or (s>=123 and s<=126):
    s3=chr(s)
    print("special charcter is",s3)

    ReplyDelete
  22. -Ajay Upadhyay
    #Programm for convert lower case to upper and upper case to lower
    int = input("Enter your name :")
    for i in range(0,len(int)):
    s=ord(int[i])
    if s<=96:
    s = s + 32
    else:
    s = s - 32
    t=chr(s)
    print(t)

    ReplyDelete
  23. #Shivam Shukla
    #WAP to count total vowel and consonant in String?
    val= 'Welcome' #['w','e','l','c','o','m','e']
    vowel=consonant=0
    for i in val:
    k=ord(i);
    if((k>=65 and k<=90) or (k>=97 and k<=122)):
    if(k>=65 and k<=90):
    i=chr(k+32);
    if i=='a' or i=='e' or i=='i' or i=='o' or i=='u':
    vowel+=1;
    else:
    consonant+=1;
    print("vowel",vowel,"consonant",consonant);

    ReplyDelete
  24. #Shivam Shukla
    #WAP to find max char in String?
    val= 'ramesh';
    count=0;
    for i in val:
    count+=1;
    k=val[0];
    for i in range(1,count):
    if(k<val[i]):
    k=val[i];
    print("Max char is : ",k);

    ReplyDelete
  25. #Shivam Shukla
    #2.1) WAP to check palindrome in String?
    #Example : madam(Correct), Madam(Incorrect)
    val="madam";
    count=0
    for i in val:
    count+=1;
    for i in range(0,count//2):
    if(val[i]!=val[count-1-i]):
    print("It's not a palindrome...");
    break;
    else:
    print("It's a palindrome...")

    ReplyDelete
  26. #2.2) WAP to check palindrome in String?
    #Example : madam(Correct), mAdam(Correct)
    val="mAdam";
    count=0
    for i in val:
    count+=1;
    for i in range(0,count//2):
    k=val[i]
    if(ord(k)>=65 and ord(k)<=90):
    k=chr(ord(k)+32);
    if(k!=val[count-1-i]):
    print("It's not a palindrome...");
    break;
    else:
    print("It's a palindrome...")

    ReplyDelete
  27. #Shivam Shukla
    #3.1) WAP to convert a string from upper case to lower case --or-- all's lower case...??
    val1="ShriVashu1"
    val2=''
    for i in val1:
    k=ord(i)
    val2 = val2+chr(k+32) if(k>=65 and k<=90) else val2+i
    print(val2)

    ReplyDelete
  28. #3.2) WAP to convert a string from lower case to upper case --or-- all's upper case...??
    val1="ShriVashu1"
    val2=''
    for i in val1:
    k=ord(i)
    val2 = val2+chr(k-32) if(k>=97 and k<=122) else val2+i
    print(val2)

    ReplyDelete
  29. #Shivam Shukla
    #3.2) WAP to convert a string from lower case to upper case --or-- all's upper case...??
    val1="ShriVashu1"
    val2=''
    for i in val1:
    k=ord(i)
    val2 = val2+chr(k-32) if(k>=97 and k<=122) else val2+i
    print(val2)

    ReplyDelete
  30. #Shivam Shukla
    #3.3) WAP to convert a string from all charactor's if upper case then lower case and if in lower case then upper case...??
    val1="ShriVashu1"
    val2=''
    for i in val1:
    k=ord(i)
    if(k>=65 and k<=90):
    val2+=chr(k+32)
    elif(k>=97 and k<=122):
    val2+=chr(k-32)
    else:
    val2+=i
    print(val2)

    ReplyDelete
  31. #Shivam Shukla
    #4.1) WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)?
    #Examples : ShriVashu > tisjwbtiv | ShriVashu1 > tisjwbtiv1
    val1='ShriVashu1'
    val2=''
    for i in val1:
    k=ord(i);
    if((k>=65 and k<=90) or (k>=97 and k<=122)):
    if(k>=65 and k<=90):
    if(k==90):
    k=65;
    k=k+32;
    val2+=chr(k+1);
    else:
    val2+=chr(k);
    print(val2);

    ReplyDelete
  32. #Shivam Shukla
    #4.2) WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)?
    #Examples : ShriVashu > TisjWbtiv | ShriVashu1 > TisjWbtiv1
    val1='ShriVashu1'
    val2=''
    for i in val1:
    k=ord(i)
    if(k>=65 and k<=90):
    if(k==90):
    k=65;
    val2+=chr(k+1)
    elif(k>=97 and k<=122):
    if(k==122):
    k=97;
    val2+=chr(k+1)
    else:
    val2+=chr(k)
    print(val2)

    ReplyDelete
  33. #Shivam Shukla
    #5) WAP to extract numeric, alphabets, and special char in separate string in any String?
    val='$ShriVashu#3108@'
    num='';
    alpha='';
    spchr='';
    for i in val:
    k=ord(i)
    if(k>=48 and k<=57):
    num+=i;
    continue;
    elif((k>=65 and k<=90) or (k>=97 and k<=122)):
    alpha+=i;
    continue;
    else:
    spchr+=i;
    print("numbers :",num,"\nalphabets :",alpha,"\n special charactor's :",spchr)

    ReplyDelete
  34. #Shivam Shukla
    #6) WAP to display a number of repeated char in String?
    #hello >> h-1 e-1 l-2 o-1
    val1='hello';
    val2='';
    for i in range(0,len(val1)):
    s=0;
    for j in val2:
    if(val1[i]==j):
    s=1;
    break;
    if(s==1):
    continue;
    s=0;
    for j in range(i,len(val1)):
    if(val1[i]==val1[j]):
    s+=1;
    print(val1[i],"-",s);
    val2+=val1[i]

    ReplyDelete
  35. #Shivam Shukla
    #7) WAP to validate emaild?
    Valid="@gmail.com";
    Email=input("Enter Email Id : ");
    v=len(Valid);
    e=len(Email);
    if(e>v):
    for i in range(0,v):
    if(Valid[i]!=Email[(e-v)+i]):
    print("Invalid Email");
    break;
    else:
    print("Valid Email")
    else:
    print("Invalid Email")

    ReplyDelete
  36. #Abhishek Singh
    #1)WAP to reverse string where vowel will be in the same position?
    s=input("Enter any Name:::")
    s1=""
    vowel="aeiouAEIOU"
    lnt=len(s)
    i=lnt

    for j in range(0,lnt):
    if(s[j] in vowel):
    s1=s1+s[j]
    else:
    while i>0:
    i-=1
    if (s[i] in vowel)==False:
    break
    s1=s1+s[i]
    print(s1)

    ReplyDelete
  37. # Ankit Saxena
    # count total vowel and consonant in String
    a=input("Enter your name:")
    vowel=0
    cons=0
    for i in range(0,len(a)):
    if(a[i]!=" "):
    if(a[i]=="a" or a[i]=="i" or a[i]=="o"or a[i]=="u"
    or a[i]=="A" or a[i]=="E" or a[i]=="O" or a[i]=="U"):
    vowel=vowel+1

    else:
    cons=cons+1
    print("Total Vowels=",vowel)
    print("Total Consonents=",cons)

    ReplyDelete
  38. #Shivam Shukla
    #1)WAP to reverse string where vowel will be in the same position?
    #for example - ramesh > hasemr
    val="shrivashu";
    list1=''
    list2=''
    for i in range(len(val)-1,-1,-1):
    k=val[i];
    if(not(k=='a' or k=='e' or k=='i' or k=='o' or k=='u')):
    list1+=val[i]
    s=0
    for i in range(0,len(val)):
    j=val[i]
    if(j=='a' or j=='e' or j=='i' or j=='o' or j=='u'):
    list2+=j;
    else:
    list2+=list1[s]
    s+=1
    print(list2)

    ReplyDelete
  39. #Shivam Shukla
    #8) WAP to display a strength of password that password is weak, medium, and Strong according to predefined cases?
    #Strong (at least 3 special char, one upper case char and numeric is mandatory, length minimum 6)
    #Medium (at least 2 special char, length minimum 6)

    '''fName='Shivam'; #input("Enter First Name : ");
    lName='Shukla'; #input("Enter Last Name : ");
    User='ShriVashu'; #input("Enter User Id : ");'''

    PassWord=input("Enter your Password : ");
    Medium=Strong=0
    spChar=toCase=upCase=Num=nonCon=0
    for i in range(0,len(PassWord)):
    k=ord(PassWord[i]);
    if(k>=48 and k<=57):
    Num+=1;
    elif((k>=65 and k<=90) or (k>=97 and k<=122)):
    if(k>=65 and k<=90):
    upCase=1;
    toCase+=1;
    else:
    spChar+=1;
    if(len(PassWord)>=6 and spChar>=3 and upCase==1 and Num>0):
    print("High Password")
    elif(len(PassWord)>=6 and spChar>=2):
    print("Medium Password!")
    else:
    print("Week Password!")

    ReplyDelete
  40. #Abhishek Singh
    #6) WAP to display a number of repeated char in String?
    s="mangalam"
    s1=""

    for i in range(0,len(s)):
    if (s[i] in s1)==False:
    s1=s1+s[i]

    for j in range(0,len(s1)):
    count=0
    for k in range(0,len(s)):
    if(s1[j]==s[k]):
    count+=1
    print(s1[j],":repeated ",count," times")

    ReplyDelete
  41. #Abhishek Kumar
    #3) WAP to convert a string from upper case to lower case and lower case to upper case?
    #Program takes user choice to convert all characters of String to either UPPER CASE or LOWER CASE except special characters
    s=input("Enter a word:::")
    s1=""
    d=ord('a')-ord('A')
    ch=input("Enter user choice for upper/lower:::(u/l):::")

    for i in range(0,len(s)):

    if ch=='l':
    if ord(s[i])>=ord('A') and ord(s[i])<=ord('Z'):
    s1=s1+chr(ord(s[i])+d)
    else:
    s1=s1+s[i]

    elif ch=='u':
    if ord(s[i])>=ord('a') and ord(s[i])<=ord('z'):
    s1=s1+chr(ord(s[i])-d)
    else:
    s1=s1+s[i]
    else:
    s1=s1+s[i]

    print(s1)

    ReplyDelete
  42. #Shivam Shukla
    #7.1) WAP to validate emaild?
    #Note : if we have only '@gmail.com' in last.....
    Valid="@gmail.com";
    Email=input("Enter Email Id : ");
    v=len(Valid);
    e=len(Email);
    if(e>v):
    for i in range(0,v):
    if(Valid[i]!=Email[(e-v)+i]):
    print("Invalid Email");
    break;
    else:
    print("Valid Email")
    else:
    print("Invalid Email")

    ReplyDelete
  43. #Shivam Shukla
    #7.2) WAP to validate emaild?
    Email=input("Enter Email Id : ");
    e=len(Email);
    fP=sP=tP=Exit=0;
    for i in range(0,e):
    k=Email[i];
    if(fP>0 or k!='@'):
    fP+=1;
    if(sP>0 or k=='@'):
    if(sP>0 and k=='@'):
    Exit=1;
    break;
    sP+=1;
    if(sP>1 and tP>0 or k=='.'):
    tP+=1;
    print("Exit :", "Applied" if(Exit==1) else "Not Applied" ," | before '@' :",fP-sP," | between '@' and '.' :",sP-1-tP," | after '.' :",tP-1);
    if(Exit==0 and fP-sP>0 and sP-tP-1>0 and tP-1>0):
    print(">> your Mail Id is Valid.....")
    else:
    print(">> your Mail Id is Invalid.....")

    ReplyDelete
  44. #8.2) WAP to display a strength of password that password is weak, medium, and Strong according to predefined cases?
    #Strong (at least 3 special char, non-consecutive, not belonging with first name and Lastname, one upper case char and numeric is mandatory, length minimum 6)
    #Medium (at least 2 special char, non-consecutive, length minimum 6)

    fName='shivam'; #input("Enter First Name : ");
    lName='shukla'; #input("Enter Last Name : ");
    User='ShriVashu07'; #input("Enter User Id : ");

    PassWord=input("Enter your Password : ");
    Medium=Strong=0
    spChar=toCase=upCase=Num=nonCon=0
    for i in range(0,len(PassWord)):
    k=ord(PassWord[i]);
    if(k>=48 and k<=57):
    Num+=1;
    elif((k>=65 and k<=90) or (k>=97 and k<=122)):
    if(k>=65 and k<=90):
    upCase=1;
    toCase+=1;
    else:
    spChar+=1;

    fVal=lVal=fExit=lExit=0
    for i in range(0,len(PassWord) - (len(fName) if(len(lName)>len(fName)) else len(lName))+1):
    if(fExit==0):
    for j in range(0,len(fName)):
    if(PassWord[i+j]==fName[j]):
    fVal+=1;
    if(fVal==len(fName)):
    print("First Name Matched!");
    fExit=1;
    if(lExit==0):
    for j in range(0,len(lName)):
    if(PassWord[i+j]==lName[j]):
    lVal+=1;
    if(lVal==len(lName)):
    print("Second Name Matched!");
    lExit=1;


    if(fExit==0 and lExit==0 and len(PassWord)>=6 and spChar>=3 and upCase==1 and Num>0):
    print("High Password")
    elif(fExit==0 and lExit==0 and len(PassWord)>=6 and spChar>=2):
    print("Medium Password!")
    else:
    print("Week Password!")

    ReplyDelete
  45. #Shivam Shukla
    #4.1) WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)?
    #Examples : ShriVashu > tisjwbtiv | ShriVashu1 > tisjwbtiv1
    val1='aAzZ1'
    val2=''
    for i in val1:
    k=ord(i);
    if((k>=65 and k<=90) or (k>=97 and k<=122)):
    if(k>=65 and k<=90):
    k=k+32;
    val2 = val2+'a' if(k==122) else val2+chr(k+1)
    else:
    val2+=chr(k);
    print(val2);

    ReplyDelete
  46. #Shivam Shukla
    #4.2) WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)?
    #Examples : ShriVashu > TisjWbtiv | ShriVashu1 > TisjWbtiv1
    val1='ShriVashu1'
    val2=''
    for i in val1:
    k=ord(i)
    if(k>=65 and k<=90):
    val2 = val2+'A' if(k==90) else val2+chr(k+1)
    elif(k>=97 and k<=122):
    val2 = val2+'a' if(k==122) else val2+chr(k+1)
    else:
    val2+=chr(k)
    print(val2)

    ReplyDelete
  47. WAP to check palindrome in String

    a=input("enter name")
    s=len(a)//2
    rev=-1
    for i in range (0,s):
    if a[i]==a[rev]:
    rev=rev-1

    else:
    print("no")
    break
    else:
    print("palindrome")

    ReplyDelete
  48. WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)

    s='NISHI'
    a=''
    for i in range(0,len(s)):
    a=a+chr(ord(s[i])+1)
    print(a)

    ReplyDelete
  49. WAP to extract numeric, alphabets, and special char in separate string in any String

    a='11@green#park'
    n=''
    s=''
    l=''
    for i in a:
    if i.isalpha():
    l=l+i
    elif i.isdigit():
    n=n+i
    else:
    s=s+i
    print("alphabets:",l)
    print("number:",n)
    print("special:",s)

    ReplyDelete
  50. s=input('"enter a word"')
    g=""
    c=5
    for i in range(0,len(s)):
    if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
    g+=s[i]
    else:
    if s[c-i]=='a' or s[c-i]=='e'or s[c-i]=='i' or s[c-i]=='o' or s[c-i]=='u':
    g+=s[i]
    else:
    g=g+s[c-i]
    print(g)

    ReplyDelete
  51. s="naman"
    c=len(s)-1
    f=True
    for i in range(0,len(s)//2):
    if s[i]!=s[c-i]:
    f=False
    break;
    if f:
    print("pallindrom")
    else:
    print("np")

    ReplyDelete
  52. s=input("enter string")
    s1=""
    for i in range(0,len(s)):
    s1=s1+chr(ord(s[i])+32)
    print(s1)

    ReplyDelete
  53. s=input("enter a character")
    s1=""
    for i in range(0,len(s)):
    s1=s1+chr(ord(s[i])+1)
    print(s1)

    ReplyDelete
  54. x=input("enter any word")
    a=''
    f=''
    o=''
    for i in range(0,len(x)):
    s=ord(x[i])
    if s>=48 and s<=57:
    f=chr(s)
    print("number",f)
    elif(s>=65 and s<=90) or (s>=97 and s<=122):
    a=chr(s)
    print("alphabet",a)
    elif(s>=32 and s<=47) or (s>=58 and s<=64) or (s>=123 and s<=126):
    o=chr(s)
    print("special charcter",o)

    ReplyDelete
  55. Emailid Validation Program in Python:-
    s="sss@gmail.com"
    dotpos=-1
    atpos=-1
    c=0
    for i in range(0,len(s)):
    if s[i]=='.':
    dotpos=i
    if s[i]=='@':
    atpos=i
    c=c+1

    #print(dotpos,atpos,c)

    if dotpos==-1 or atpos==-1 or dotpos1 or atpos<3:
    print("Invalid email id")
    else:
    print("emailid is valid")

    ReplyDelete
  56. s="gkd@gmail.com"
    dotpos=-1
    atpos=-1
    c=0
    for i in range(0,len(s)):
    if s[i]=='.':
    dotpos=i
    if s[i]=='@':
    atpos=i
    c=c+1
    #print(dotpos,atpos,c)
    if dotpos==-1 or atpos==-1 or dotpos1 or atpos<3:
    print("invalid email id")
    else:
    print("emailid is valid")

    ReplyDelete
  57. #WAP to validate the mobile number?
    m=input("enter 10 digits mobile number:=")
    t=('1','2','3','4','5','6','7','8','9','0')
    a=[]
    b=10
    if m[0]=='0':
    print("invailid mobile number")
    else:
    for i in range(0,len(m)):
    if m[i] in t:
    a.append(m[i])
    if i==len(m)-1:
    print("valid mobile number")
    continue
    else:
    print("invailid mobile number")
    break

    ReplyDelete
  58. #WAP to reverse string where vowel will be in the same position?
    a=input("enter string:-")
    b=0
    v=0
    l=[]
    for i in range(0,len(a)):
    if a[i]=='a'or a[i]=='e'or a[i]=='i'or a[i]=='o'or a[i]=='u':
    b=l.append(a[i])
    else:
    b=l.append(a[i])
    b=l[::-1]
    print(b)

    ReplyDelete
  59. #WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)
    s=input("enter string:-")
    s1=''
    z=''
    for i in range(0,len(s)):
    if ord(z)==122:
    z=z-25
    s1=s1+chr(ord(s[i])+1)

    print(s1)

    ReplyDelete
  60. #palindrome or not
    s=input("enter string:-")
    l=[]
    l1=[]
    for i in range(0,len(s)):
    l.append(s[i])
    l1=l[::-1]
    if l==l1:
    print("palindrome")
    else:
    print("not palindrome")

    ReplyDelete
  61. s='ramesh'
    m=s[0]
    for i in range(1,len(s)):
    if ord(m)<ord(s[i]):
    m=s[i]
    print(m)

    ReplyDelete
  62. #WAP to convert a string from upper case to lower case and lower case to upper case
    s=input("enter capital string:-")
    s1=''
    s2=''
    for i in range(0,len(s)):
    s1=s1+chr(ord(s[i])+32)
    s2=s2+chr(ord(s1[i])-32)
    print(s1)
    print(s2)

    ReplyDelete
  63. #WAP to validate email?
    s=input("enter email id:-")
    a=0
    d=0
    for i in range(0,len(s)):
    if s[i]=='@':
    a=i
    if s[i]=='.':
    d=i
    if a>0 and (d-a)>=2:
    print("vailid email id")
    else:
    print("invailid email id")

    ReplyDelete
  64. #WAP to count the total vowel and consonant in String?
    s=input("enter string:-")
    v=0
    c=0
    for i in range(0,len(s)):
    if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
    v=v+1
    else:
    c=c+1

    print("total vowel is:-",v,"total consonent is:-",c)

    ReplyDelete
  65. #check mobile number frequency
    l=[]
    num=int(input("enter any mobile no:-"))
    while num>0:
    a=num%10
    l.append(a)
    num=num//10
    b=l[::-1]
    print("----Number----Repeated----")
    for i in range(0,10):
    count=0
    for j in range(0,len(b)):
    if b[j]==i:
    count=count+1
    print(" ",i," ",count)
    print("Total Number is:-",len(l))

    ReplyDelete
  66. WAP to extract numeric, alphabets, and special char in separate string in any String?
    Sol:-s = "abcd123@7$f"
    s1=""
    s2=""
    s3=""
    for i in s:
    if i.isalpha():
    s1=s1+str(i)
    elif i.isdigit():
    s2=s2+str(i)
    else:
    s3=s3+str(i)
    print(s1)
    print(s2)
    print(s3)

    ReplyDelete
  67. #WAP to check palindrome in String?
    s=input("Enter string:")
    r =""
    for i in s:
    r = i + r
    print("Reverse String:",r)
    if(s==r):
    print("String is palindrome")
    else:
    print("String is not palindrome")

    ReplyDelete
  68. #WAP to convert a string from upper case to lower case and lower case to upper case?
    #Upper to Lower
    s=input("Enter String in UPPER CASE:")
    a=""
    for i in s:
    a=a+chr(ord(i)+32)
    print(a)

    #Lower to Upper
    s=input("Enter String in LOWER CASE:")
    a=""
    for i in s:
    a=a+chr(ord(i)-32)
    print(a)

    ReplyDelete
  69. #WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)?
    s=input("Enter String:")
    a=""
    for i in s:
    if i=='z' or i=='Z':
    a=a+chr(ord(i)-25)
    else:
    a=a+chr(ord(i)+1)
    print(a)

    ReplyDelete
  70. # WAP to extract numeric, alphabets, and special char in separate string in any String?
    s=input("Enter String:")
    c=''
    n=''
    sc=''
    for i in range(0,len(s)):
    s1=ord(s[i])
    if (s1>=65 and s1<=90) or (s1>=97 and s1<=122):
    c=c+s[i]
    elif s1>=48 and s1<=57:
    n=n+s[i]
    elif (s1>=32 and s1<=47) or (s1>=58 and s1<=64) or (s1>=123 and s1<=126):
    sc=sc+s[i]
    print("Character in String",c)
    print("Numeric in String",n)
    print("Special character in String",sc)

    ReplyDelete
  71. #WAP to reverse string where vowel will be in the same position?

    st="sachin"
    s1=''
    c=5
    for i in range(0,len(st)):
    if st[i] in ('a','e','i','o','u'):
    s1=s1+st[i]
    else:
    if st[c-i] in ('a','e','i','o','u'):
    s1=s1+st[i]

    else:
    s1=s1+st[c-i]

    print(s1)

    ReplyDelete
  72. s=input("Enter any String")
    m=s[0]
    for i in range (0,len(s)):
    print(ord(s[i])," ",end="")
    if m<s[i]:
    m=s[i]
    print()

    print("Maximum",m)
    print(ord(m))

    ReplyDelete
  73. #WAP to check palindrome in String?
    s=input("Enter any name")
    for i in range (0,len(s)):
    if s[:]==s[::-1]:
    print ("pl",s)
    break
    else:
    print("not pl",s)

    ReplyDelete
  74. WAP to replace the string char from the next consecutive String char (if char will be z then replace by a)?

    print("Input a String capital or small without space")
    s=input("input ")
    st=""

    for i in range(0,len(s)):
    if (ord(s[i])>=65 and ord(s[i])<90) or (ord(s[i])>=97 and ord(s[i])<122):
    st=st+chr(ord(s[i])+1)
    if ord(s[i])==90 or ord(s[i])==122:
    st=st+chr(ord(s[i])-25)
    print(st)

    ReplyDelete
  75. WAP to extract numeric, alphabets, and special char in separate string in any String?

    s=input("Input a mixed string like email address: ")
    a=""
    n=""
    c=""
    for i in range(0,len(s)):
    if (ord(s[i])>=65 and ord(s[i])<=90) or (ord(s[i])>=97 and ord(s[i])<=122):
    a=a+s[i]
    elif ord(s[i])>=48 and ord(s[i])<=57:
    n=n+s[i]
    else:
    c=c+s[i]
    print("alphabetic characters are: ",a)
    print("numbers are: ",n)
    print("special characters are: ",c)

    ReplyDelete
  76. #3) WAP to convert a string from upper case to lower case and lower case to upper case?
    #Lower to upper

    s="UnderStand"

    c=""


    for i in range(0,len(s)):
    k=ord(s[i])
    if k>65 and k<90:
    c=c+chr(k+32)
    else:
    c=c+chr(k-32)

    print (c)

    ReplyDelete
  77. #4) WAP to replace the string char from the next consecutive String char
    #(if char will be z then replace by a)

    s="abcz"
    c= ""
    for i in range (0,len(s)):
    k=ord(s[i])
    if k==90:
    k=64
    if k==122:
    k=96
    c=c+chr(k+1)
    print(c)

    ReplyDelete
  78. #5) WAP to extract
    #Numeric, alphabets, and special char in separate string in any String
    x="Und1@erSt276#$%and"
    n=""
    a=""
    s=""


    for i in x:
    k=ord(i)
    print(k)
    if k>65 and k<90 or k>97 and k<122:
    a=a+ ","+chr(k)
    if (k>48 and k<57):
    n=n+ ","+chr(k)
    if (k>9 and k<47)or(k>58 and k<64)or(k>91 and k<96)or (k>123 and k<126):
    s=s+","+chr(k)


    print ("numbers:",n,"\n","alphabets:",a,"\n","Special char:",s)

    ReplyDelete
  79. #5) WAP to extract
    #Numeric, alphabets, and special char in separate string in any String
    x="Und1@erSt276#$%and"
    n=""
    a=""
    s=""


    for i in x:
    k=ord(i)
    print(k)
    if k>=65 and k<=90 or k>=97 and k<=122:
    a=a+ ","+chr(k)
    elif (k>48 and k<57):
    n=n+ ","+chr(k)
    else:
    s=s+","+chr(k)


    print ("numbers:",n,"\n","alphabets:",a,"\n","Special char:",s)

    ReplyDelete
  80. #WAP to validate emaild?
    #(@, ., the position of @ should be lesser of last dot position)
    e=input("Enter your email id:")
    k=len(e)
    for i in range (0,k):
    if e[i]=='@':
    a=i
    print ("Index value of @ :",i)

    if e[i]=='.' :
    d=i
    print ("Index value of . :",i)

    if a<d:
    print ("Email entered successfuly")

    else:
    print("Invalid email")

    ReplyDelete
  81. ##WAP to count total vowel and consonant in String?

    s='welcome' #['w','e','l','c','o','m','e']
    vowel=0
    consonent=0
    #d=['a','e','i','o','u']
    for i in s :
    if i in ['a','e','i','o','u'] :
    vowel=vowel+1
    else:
    consonent=consonent+1
    print(vowel,consonent)

    ReplyDelete
  82. ##2) WAP to check palindrome in String?

    p="naman"
    for i in range(0,len(p)//2):
    if p[i]!= p[(len(p)-1-i)]:
    print("Not Palindrom")
    break
    else:
    print("Palindrom")

    ReplyDelete
  83. ## WAP to display a strength of password that password is weak, medium, and Strong according to predefined cases?

    ##1.Strong (at least 3 special char, non-consecutive, not belonging with first name and Lastname, one upper case char and numeric is mandatory, length minimum 6)
    ##2.Medium (at least 2 special char, non-consecutive, length minimum 6)



    print ('enter password')
    print ()
    print ()
    print ('the password must be at least 6, and no more than 12 characters long')
    print ()

    password = input ('type your password ....')


    weak = 'weak'
    med = 'medium'
    strong = 'strong'

    if len(password) >12:
    print ('password is too long It must be between 6 and 12 characters')

    elif len(password) <6:
    print ('password is too short It must be between 6 and 12 characters')

    elif len(password) >=6 and len(password) <= 12:
    print ('password ok')

    if password.lower()== password or password.upper()==password or password.isalnum()==password:
    print ('password is', weak)

    elif password.lower()== password and password.upper()==password or password.isalnum()==password:
    print ('password is', med)
    else:
    password.lower()== password and password.upper()==password and password.isalnum()==password
    print ('password is', strong)

    ReplyDelete
  84. ## First 4 & last 2 char Email Id
    s=input("enter any string :- ")
    x=''
    for i in range(len(s)):
    if i<4 or i>len(s)-3:
    x=x+s[i]


    print(f"Email Id :-{x}@gmail.com")

    ReplyDelete
Post a Comment