Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

String Concept in Python:-


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)     


......................................................................
MOST OF THE STRING PROGRAM WILL BE RELATED WITH ASCII CODE HENCE PYTHON PROVIDE TWO DIFFERENT METHOD TO PERFORM OPERATION FROM
ASCII TO CHAR AND CHAR TO ASCII

print(ord('a'))  #97   #char to ascii
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="";
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':
        s1+=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':
            s1+=s[i]
        else:
            s1=s1+s[c-i]
         

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


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)

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?

6)  WAP to display a number of repeated char in String?
hello     h 1 e 1 l 2 o 1

7)  WAP to validate emaild?

8)  WAP to display a strength of password that password is weak, medium, and Strong according to predefined cases?

String (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)










18 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  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

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post