0% found this document useful (0 votes)
1 views1 page

Python Assignment by 124103023

The document contains a series of Python programs that perform various string manipulations including reversing a string, checking for palindromes, removing duplicates, checking for anagrams, finding string length, printing even length words, and determining the maximum frequency character in a string. Each program includes user input prompts and outputs the results directly. The examples provided illustrate the functionality of each program with sample inputs and outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

Python Assignment by 124103023

The document contains a series of Python programs that perform various string manipulations including reversing a string, checking for palindromes, removing duplicates, checking for anagrams, finding string length, printing even length words, and determining the maximum frequency character in a string. Each program includes user input prompts and outputs the results directly. The examples provided illustrate the functionality of each program with sample inputs and outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1. Write a program to reverse the given string.

str=input("enter the string")


length=len(str) enter the string python
print("the reverse is") the reverse is:
for i in range(length):
print(str[length-1-i],end="") nohtyp

2. Write a program to find the string is palindrome or not.

str=input("enter the string")


length=len(str)
rev=""
enter the stringnitin
for i in range(length): the reverse is
rev+= str[length-1-i] nitin
print("the reverse is ")
yes is a palindrome
print(rev)
if(str==rev):
print(" yes is a palindrome")
else:
print("nh")

3. Write a program to remove the duplicate from the given


string.

def remove_duplicates(s):
seen = set()
result = ""

for char in s: Enter the string: hello


if char not in seen: String after removing duplicates: helo
result += char
seen.add(char) # Mark character as seen

return result

# Input from user


str_input = input("Enter the string: ")
print("String after removing duplicates:",
remove_duplicates(str_input))

4. Write a program to check the given string is Anagram or


not.

def isanagram(s1,s2):
if(len(s1)!=len(s2)):
return False
return sorted(s1)==sorted(s2)
enter the first string:gum
s1=input("enter the first string:")
s2=input("enter the second string:")
enter the second string:mug
yes it is a anagram
if isanagram(s1,s2):
print("yes it is a anagram")

else:
print("no it is not anagram")

Double-tap to enter text

5. Write a program to find the length of the string.

enter the value of string goodmorning


str=input("enter the value of string") 11
length=len(str)
print(length)

6. Write a program to print the even length word in the given


string.

str=input("enter the value of string:") enter the value of string:ankit


length=len(str)
for i in range(1,length,2): ni
print(str[i],end="")
i=i+1

7. Write a program to find the maximum frequency character


in the string.

enter the string:hellohowareyou


def max_frequency(s): the max frewuency is of 'o'appears 3
return max(set(s),key=s.count)

str=input("enter the string:").replace(" ","")


char=max_frequency(str)
print(f"the max frewuency is of '{char}'appears {str.count(char)}")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy