Question

You can swap only two consecutive elements. Write a program in PYTHON to convert a string...

You can swap only two consecutive elements. Write a program in PYTHON to convert a string into another string (both strings will be anagrams of each other). E.g. GUM to MUG

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Description-: The approach we have followed in order to develop program to check anagrams of two strings are as follows-:

1) We will prompt users to enter two strings.

2)We will use sort() to sort two strings into lists.

3) After that sorted list will be compared and check if they are equal.

4) Finally we will use print ( ) to print the final outcome.

s1=input("Enter first string")
s2=input("Enter second string")
def anagram(str1, str2):
str1 = list(str1)
str1.sort()
str2 = list(str2)
str2.sort()

if str1 == str2:
print("both strings will be anagrams of each other")
else:
print("both strings will not be anagrams of each other")

anagram(s1,s2)

#Kindly upvote if you find it helpful.

Add a comment
Know the answer?
Add Answer to:
You can swap only two consecutive elements. Write a program in PYTHON to convert a string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Swap Cases - Write a python program to swap cases. LowerCase letters to Upper case and...

    Swap Cases - Write a python program to swap cases. LowerCase letters to Upper case and vice versa (10 points) Input : Www.PyDev.com Output: wWW.pYdEV.COM Input: Pythonist 2 Output: pYTHONIST 2 b) Manipulate Strings - Insert a sequence of characters into the specified position in the given String(10 points) Input : First Line contains the string to be manipulated Second Line contains the string to be inserted and the position Number Output : The modified string Sample Input & Output:-...

  • PYTHON You are to write a program that will analyze the frequency of letters in a...

    PYTHON You are to write a program that will analyze the frequency of letters in a string. The user will enter a string, your program will output the number of times the letters of the alphabet appear in that string. The user is to enter a string that has upper or lower case letters only, no spaces or other characters. You should convert the string entered to all lowercase letters before you conduct your analysis.

  • In PYTHON ONLY PLEASE You will use a dictionary in Python You only have string in Python so you have to use a string dat...

    In PYTHON ONLY PLEASE You will use a dictionary in Python You only have string in Python so you have to use a string data type Use a Switch statement.A switch statement is just another way of writing an IF statement. The user will enter f, s, j, or r from the keyboard for freshman, sophomore, junior, or senior. Use character data type for c++. Then you can say something like: char level ='f'; level=toupper(level); You would need a loop...

  • Write a Python program to convert a pdf file to html page. Write Code in Python...

    Write a Python program to convert a pdf file to html page. Write Code in Python Language Only. Please Send Screenshots also Good Answer is Appreciable...

  • Can you write a program to convert a string from uppercase to lowercase and lowercase to...

    Can you write a program to convert a string from uppercase to lowercase and lowercase to uppercase depending on the user's input? In simple C++ please So for example if the input is Hello then the output should be hELLO

  • Python code Write a program that will ask the user to input two strings, assign the...

    Python code Write a program that will ask the user to input two strings, assign the strings to variables m and n If the first or second string is less than 10 characters, the program must output a warning message that the string is too short The program must join the strings m and n with the join function The output must be displayed. Please name the program and provide at least one code comment (10)

  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

  • 3. (4 pt) Write a Python program to find the longest common prefix string amongst an...

    3. (4 pt) Write a Python program to find the longest common prefix string amongst an array of strings. You are required to write a function max- Prefix, which when called by the main program would get the array of strings as input and return a single string that would either be the longest 1 common prefix or a string ”NULL” depending on the input. (Note: The array is input from the keyboard in the main program (930)) If there...

  • Simple Python Program Working with strings Write a Python program to read in a number of...

    Simple Python Program Working with strings Write a Python program to read in a number of strings from the user. Stop when the user enters “Done”. Then check if each of the strings contains all the letters of the alphabet. Print the results in the form of a dictionary, where they keys are the strings and the values are the Truth Value for the string, which you just calculated. Sample Run: Enter the strings: taco cat The quick brown fox...

  • Write a python program that will analyse the string input and print “accept” or “reject” based...

    Write a python program that will analyse the string input and print “accept” or “reject” based on the pattern given Accept if it fulfils the following conditions  String length 9  3 small alphabet (3 lowercase letter)  3 number (3 digit)  3 big alphabet (3 uppercase letters)  1 st alphabet should be capital  Last alphabet should be a number  Two consecutive alphabets can’t be small Reject if any of the condition is absent

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT