Question

16.43 Lab 13C: Palindromes with Files and Functions Overview This is a demonstration of reading and writing files, along with
Lab 13C: Palindromes with Files and Functions E zyBooks catalog Help/FAQ Create a program to read each line of an input file,
0 0
Add a comment Improve this question Transcribed image text
Answer #1

******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As HOMEWORKLIB RULES expert answering guidelines,Experts are supposed to answer only certain number of questions/sub-parts in a post.Please raise the remaining as a new question as HOMEWORKLIB RULES guidelines.
******************************************************************************************

f= open("myinput.txt","r")

g= open("myoutput.txt","w")

lines = [x[:-1] for x in f.readlines()]

for word in lines:

i=0

j=len(word)-1

# print(word)

while i<j:

if word[i]==' ':

while i<len(word) and word[i]==' ':

i+=1

if word[j]==' ':

while j>=0 and word[j]==' ':

j-=1

if(word[i] != word[j]):

print(word+" ==> Not a palindrome")

g.write("Not a palindrome")

break

i+=1

j-=1

if i>=j:

print(word+" ==> palindrome")

g.write("palindrome")

Add a comment
Know the answer?
Add Answer to:
16.43 Lab 13C: Palindromes with Files and Functions Overview This is a demonstration of reading and...
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
  • In Python Please! 16.42 Lab 13B: Palindromes with Files Overview This is a demonstration of reading...

    In Python Please! 16.42 Lab 13B: Palindromes with Files Overview This is a demonstration of reading and writing files. Objectives Be able to read from an input file, perform string manipulation on each line of the file, and write to an output file. Provided input file: A single input file named myinput.txt is provided that contains a few lines of text. bob sees over the moon never odd or even statistics dr awkward Provided output file: A single output file...

  • Hint: User will enter certain number of random words, you need to read the input as...

    Hint: User will enter certain number of random words, you need to read the input as string and evaluate based on the following instructions. Write a void method called palindromeCheck that takes NO argument. The method should have functionality to check whether or not the word is a palindrome and print to the screen all of the palindromes, one per line. Also, the last line of the output should have the message: “There are x palindromes out of y words...

  • Implement the Stack Class with an ArrayList instead of an array, including the following functions: -empty...

    Implement the Stack Class with an ArrayList instead of an array, including the following functions: -empty -push -peek -pop -overrided toString() function which returns all of the stack's contents Things to note: -You no longer need a size. -You no longer need to define a constant DEFAULT_CAPACITY. since ArrayLists grow dynamically. -Whenever possible, use ArrayList functions instead of the [ ] (index operator) to implement your stack functions Then write a driver program to do palindrome check. A string is...

  • Reading and Writing Complete Files in C: The first part of the lab is to write...

    Reading and Writing Complete Files in C: The first part of the lab is to write a program to read the complete contents of a file to a string. This code will be used in subsequent coding problems. You will need 3 functions: main(), read_file() and write_file(). The main function contains the driver code. The read_file() function reads the complete contents of a file to a string. The write_file() writes the complete contents of a string to a file. The...

  • This is a java question A palindrome is a word or phrase that reads the same...

    This is a java question A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and punctuations, and considering uppercase and lowercase versions of the same letter to be equal. For example, the following are palindromes: warts n straw radar Able was I ere I saw Elba tacocat Write a program named Palindrome.java that will accept a file (file name) from the command argument list and decide whether each line in the file is...

  • 1 of 1 15 points) Palindrome Detector. A palindrome is a phrase that reads the Pi...

    1 of 1 15 points) Palindrome Detector. A palindrome is a phrase that reads the Pi same ronwards as it does backwards. For example, "a man, a plan, a canal, Panama is a palindrome. Write a program that uses a stack to check for palindromes in each line of a text file. Try your program on the example text file "palindromes txt".Your program should output the palindromes that it finds in the document. For example: FindPalindromes( palindromes.txt") will display "a...

  • This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your...

    This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your knowledge of basic C++ programing to develop your solution. Develop a functional flowchart and then write a C++ program to solve the following problem. 1. Create a text file named file1.txt and write your brand of car (like Honda, Toyota, etc) in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your...

  • 1.) Write a recursive function named isPalindrome that will take a single string as an argument...

    1.) Write a recursive function named isPalindrome that will take a single string as an argument and determine if the argument is a palindrome. The function must return True if the argument is a palindrome, False otherwise. Recall that any string is a palindrome if its first and last characters are the same and the rest of it is also a palindrome (therefore, a single character is a palindrome): 2.) Consider a text file named samplestrings.txt that contains a collection...

  • Lab 10: ArrayLists and Files in a GUI Application For this lab, you will work on...

    Lab 10: ArrayLists and Files in a GUI Application For this lab, you will work on a simple GUI application. The starting point for your work consists of four files (TextCollage, DrawTextItem, DrawTextPanel, and SimpleFileChooser) in the code directory. These files are supposed to be in package named "textcollage". Start an Eclipse project, create a package named textcollage in that project, and copy the four files into the package. To run the program, you should run the file TextCollage.java, which...

  • C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and...

    C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and backward. Some examples of palindromes are: "radar" "able was i ere i saw elba" and, if you ignore blanks: "a man a plan a canal panama" Write a recursive function testPalindrome that returns 1 if the string stored in the array is a palindrome and 0 otherwise. The function should ignore spaces and punctuation in the string. Use the function in a complete program...

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