0% found this document useful (0 votes)
4 views

strings prog py

Uploaded by

netmirror36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

strings prog py

Uploaded by

netmirror36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q) Write a Program to Accept some String from the Keyboard and display its

Characters by Index wise (both Positive and Negative Index)


a)a = input('Enter string')
j=len(a)
for x in range(j):
print('character:',a[x],'postive direction:',x,'negative direction:',(j-x))

***********************************************************************************
*
Q) Write a Program to access each Character of String in
Forward and Backward Direction by using while Loop?
a)a = input('Enter string')
j=len(a)
x=0
while x<j:
print('character:',a[x],'postive direction:',x,'negative direction:',(j-x))
x=x+1

***********************************************************************************
Q) Write a Program to access each Character of String in
Forward and Backward Direction by using while Loop?
a)s = "Learning Python is very easy !!!"
k=len(s)
print("forward direction ")
i=0

while i<k:
print(s[i],end="")
i=i+1
i=-1
print()
print("backward direction ")
while i>=-k:
print(s[i],end="")
i-=1

***********************************************************************************
Q) Program to display all Positions of Substring in a given
Main String
a)j="bavababavabsbvsbsnshsvsvsbsb"
k=input("enter sub string")
h=len(j)
for x in range(h):
if j[x]==k:
print("found at:",x)

***********************************************************************************
Q) String Objects are Immutable then how we can change the
Content by using replace() Method
a)s="varadasfvhz"
print(s.replace("v","k"))

***********************************************************************************
*
Q1) Write a Program to Reverse the given String
Input: durga
Output: agrud
a)s="durga"
print(s[::-1])
***********************************************************************************
*
Q2) Program to Reverse Order of Words
Input: Learning Python is very Easy
Output: Easy Very is Python Learning
a)s="Learning Python is very Easy"
k=s.split(" ")
h=" ".join(k[::-1])
print(h)
***********************************************************************************
*
Q3) Program to Reverse Internal Content of each Word
Input: Durga Software Solutions
Output: agruD erawtfoS snoituloS
a)

***********************************************************************************
Q4) Write a Program to Print Characters at Odd Position and
Even Position for the given String?
a)s=input("enter the string:")
h=len(s)
for x in range(h):
if x%2==0:
print("even index at:",x,"character",s[x])
else:
print("odd index at:",x,"character",s[x])
(or)
s=input("enter the string:")
print("even index atcharacter",s[::2])
print("odd index atcharacter",s[1::2])

***********************************************************************************
Q5) Program to Merge Characters of 2 Strings into a Single
String by taking Characters alternatively
Input: s1 = "ravi"
s2 = "reja"

***********************************************************************************
*
Q6) Write a Program to Sort the Characters of the String and
First Alphabet Symbols followed by Numeric Values
Input: B4A1D3
Output: ABD134

***********************************************************************************
**
Q7) Write a Program for the following Requirement
Input: a4b3c2
Output: aaaabbbcc

***********************************************************************************
**
Q8) Write a Program to perform the following Activity
Input: a4k3b2
Outpt: aeknbd

***********************************************************************************
**
Q9) Write a Program to Remove Duplicate Characters from
the given Input String?
Input: ABCDABBCDABBBCCCDDEEEF
Output: ABCDEF

***********************************************************************************
**
Q10) Write a Program to find the Number of Occurrences of
each Character present in the given String?
Input: ABCABCABBCDE
Output: A-3,B-4,C-3,D-1,E-1

***********************************************************************************
**
Q11) Write a Program to perform the following Task?
Input: 'one two three four five six seven'
Output: 'one owt three ruof five xis seven'

***********************************************************************************
***

You might also like