Question

USING ONLY LOOPS CANNOT USE INDEXING OF STRINGS (STR) PYTHON 3 CODE IS TESTED WITH JDK...

USING ONLY LOOPS

CANNOT USE INDEXING OF STRINGS (STR)

PYTHON 3

CODE IS TESTED WITH JDK AND WILL KNOW WHEN USING FORBIDDEN CODE

 write a program called reversibleSentence

-- ask for a word from user
-- if word is the same read from left to right or right to left, then
-- print "the word is reversible", else
-- print "the word IS NOT reversible"

  HINT:

  The following program prints heo

sentence = ""
for x in "hello":
    if x != "l":
        sentence = sentence + x
print(sentence)
% reversibleSentence.py
enter a sentence: anna
the word is reversible
% reversibleSentence.py
enter a sentence: civic
the word is reversible
% reversibleSentence.py
enter a sentence: kayak
the word is reversible
% reversibleSentence.py
enter a sentence: rotator
the word is reversible
% reversibleSentence.py
enter a sentence: don't nod.
the word is reversible
% reversibleSentence.py
enter a sentence: I did, did I?
the word is reversible
% reversibleSentence.py
enter a sentence: I din't, didn't I?
the word IS NOT reversible
% reversibleSentence.py
enter a sentence: my gym!
the word is reversible
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#get user input
word = input("Enter a word: ")

#string declaration
sentence = ""

#remove the special character
for character in word:
if character.isalnum():
sentence += character

#method to check word is reversible or not
def reversibleSentence(sentence):
revString = sentence[::-1]
for x, y in zip(sentence, revString):
if x != y:
print("the word IS NOT reversible")
return False
  
print("the word is reversible")   
return True

#method calling
reversibleSentence(sentence)
  
The screenshot of the source code is given below:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
USING ONLY LOOPS CANNOT USE INDEXING OF STRINGS (STR) PYTHON 3 CODE IS TESTED WITH JDK...
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
  • Hi. Please help me solve this in python using only while loops, if statements. Can't use...

    Hi. Please help me solve this in python using only while loops, if statements. Can't use for loops and lists. In this programming assignment, you will be writing a program that prints out several shapes via text. In this PA, you will be required to use functions and parameters. This is both to reduce redundancy and to make your code clean and well-structured. Name your program shaper.py Your program should have the capability to print out three different shapes: An...

  • Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the...

    Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...

  • Here is my code to put a quote down, flip it, and reverse it. I do...

    Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...

  • how to make my code of python work probely my q is how to write a...

    how to make my code of python work probely my q is how to write a code to find the average actual water level, average error by using python and my program should be flexible where user can select the column no. If you can see in the main program, it asked which column to know the maximum or average, the column number is passed to the function. The function should look which column to do. #THIS PROGRAMMING IS ABLE...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

  • In your judgement, and given only the facts described in this case, should the management of...

    In your judgement, and given only the facts described in this case, should the management of Massey energy Company be held morally responsible for the deaths of the 29 miners? Explain in detail. Suppose that nothing more is learned about the explosion other than what is described in this case. Do you think Don Blankership should be held morally responsible for the deaths of the 29 miners? Explain in detail. Given only the facts described in this case, should the...

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