Question

Write a program that reads a word and then prints the word in reverse separated by...

  1. Write a program that reads a word and then prints the word in reverse separated by a comma. 3 pts

Note: No comma at the end of the reversed word.

Enter word: Harry

The reversed word is: y,r,r,a,H

Python keep it simple

Homework Answers

Answer #1

Code:

#take the input from user
word=input("enter the word you want to reverse: ")
#store the len of string in variable l
l=len(word)
#now create an empty string to store the result
out=""
#now start from the end of the string and decrement -1
#till we reach the starting index of the string
for i in range(l-1,-1,-1):
   #append each character to the empty string
   out= out+word[i]
   #if the character is the last character then break the loop
   if(i==0):
       break
   #append a comma after appending every character
   out=out+","
#now print the output
print("The string after modifying is: ")
print(out)

Output:

Code Screenshot:

Code Snippet:

#take the input from user
word=input("enter the word you want to reverse: ")
#store the len of string in variable l
l=len(word)
#now create an empty string to store the result
out=""
#now start from the end of the string and decrement -1
#till we reach the starting index of the string
for i in range(l-1,-1,-1):
        #append each character to the empty string
        out= out+word[i]
        #if the character is the last character then break the loop
        if(i==0):
                break
        #append a comma after appending every character
        out=out+","
#now print the output
print("The string after modifying is: ")
print(out)
Know the answer?
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
Similar Questions
Vowels and consonants Write a program that reads a word and prints the number of vowels...
Vowels and consonants Write a program that reads a word and prints the number of vowels and consonants in the word. For this exercise assume that ‘a’, ‘e’, ‘i’, ‘o’, ‘u’, and ‘y’ are vowels. For example, if the user enters the input “Harry”, the program should print “The word contains 2 vowels and 3 consonants”.
Write a python program that reads a word list and prints out all the anagrams in...
Write a python program that reads a word list and prints out all the anagrams in the word list. In earlier exercises you saw how to read a word list. Also, in earlier examples we saw how the sorted characters of a word are a useful canonical representation of an anagram (Hint: Therefore, useful as a key).
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Using the facilities of numpy, write a python program that reads the input signal as a...
Using the facilities of numpy, write a python program that reads the input signal as a space separated sequence of numbers on one line, and the system impulse response as a space separated sequence of numbers on the next line, and outputs (on one line) the output of the DT LTI system. The input lines should be interpreted as x[0] x[1] x[2] ... x[N-1] h[0] h[1] h[2] ... h[M-1] and the output should be produced in the same order: y[0]...
Write a Python program that reads in a string and determines whether the string is a...
Write a Python program that reads in a string and determines whether the string is a palindrome or not. note that a sentence that reads the same forwards and backwards by resequencing the spaces is also a palindrome and your program should consider this. sample run enter string: mom output: mom is a polindrame enter string: a nut for a jar of tuna output: a nut for a jar of tuna is a palindrome
Write a Python program that reads in the month, day, and year of a date and...
Write a Python program that reads in the month, day, and year of a date and prints it in the dd/mm/yyyy format or mm/dd/yyyy format, the format depending on the user’s preference. The program also prints the message It is a magic date If the product of month and day is equal to the last two digits of the year. For example, April 20 1980 is a magic date because April (numeric value 4) multiplied by 20 is equal to...
Write the following function and provide a program to test it (main and function in one...
Write the following function and provide a program to test it (main and function in one .py) 5 pts def readFloat(prompt) that displays the prompt string, followed by a space, reads a floating-point number in, and returns it. Below is how you’re going to call the function: salary = readFloat(“Please enter your salary:”) percentageRaise = readFloat(“What percentage raise would you like?”) print("The salary is", salary) print("The raise percentage is", percentageRaise) keep it simple, python
- Write a python program which prints all the numbers between 1 and 100 that are...
- Write a python program which prints all the numbers between 1 and 100 that are divisible by 3.
Write a c++ program that prints all possible distinct “words” that can be obtained by permuting...
Write a c++ program that prints all possible distinct “words” that can be obtained by permuting the letters of the word input by users. (Note: A “word” here refers to a sequence of letters and need not be in the dictionary.) For example: Input word to find permutations: abc acb bac bca cba cab
Please write a program that reads the file you specify and calculates how many times each...
Please write a program that reads the file you specify and calculates how many times each word stored in the file appears. However, ignore non-alphabetic words and convert uppercase letters to lowercase letters. For example, all's, Alls, alls are considered to be the same words. What is the output of the Python program when the input file is specified as "proverbs.txt"? That is, in your answer, include the source codes of your word counter program and its output. <proverbs.txt> All's...