0% found this document useful (0 votes)
37 views3 pages

Technical Communication Assignment-1 2023 (VK)

The document describes three Python programs: 1. Three ways to reverse a string - using a for loop, while loop, and slice operator. 2. A program to print the characters at odd and even positions in a string. 3. A program to merge the characters of a string into a single string by taking characters alternatively.

Uploaded by

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

Technical Communication Assignment-1 2023 (VK)

The document describes three Python programs: 1. Three ways to reverse a string - using a for loop, while loop, and slice operator. 2. A program to print the characters at odd and even positions in a string. 3. A program to merge the characters of a string into a single string by taking characters alternatively.

Uploaded by

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

EXPERIMENT:- 11

Program no.1: WAP to reverse the string using:


a) for loop
def reverse_string(str):
str1 = ""
for i in str:
str1 = i + str1
return str1
str = "AMAN"
print("The original string is: ",str)
print("The reverse string is",reverse_string(str))

Output:-

b) while loop
str = "JavaTpoint"
print ("The original string is : ",str)
reverse_String = ""
count = len(str)
while count > 0:
reverse_String += str[ count - 1 ]
count = count - 1
print ("The reversed string using a while loop is :
",reverse_String)

Output:-
c) Slice Operator
def reverse(str):
str = str[::-1]
return str
s = "JavaTpoint"
print ("The original string is : ",s)
print ("The reversed string using extended slice operator
is : ",reverse(s))

Output:-

Program no. 2: WAP to print Character at odd position and Even position.

number_of_strings = int(input("Enter no of strings: "))


for line in range(number_of_strings):
string = input("Enter string: ")
even_string = ""
odd_string = ""
for i in range(len(string)):
if i%2==0:
even_string = even_string + string[i]
else:
odd_string = odd_string + string[i]
print(even_string,odd_string)

Output:-

Program no. 3: WAP to merge character of string into a single string by taking
character alternatively.

You might also like