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
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...
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...
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
Question 1 Write a program that reads from the user the height and radius of a...
Question 1 Write a program that reads from the user the height and radius of a cylinder, and then outputs the area of this cylinder. The area of the cylinder is calculated using the formula: A=2*π*r*h+2*π*r2, where π = 3.14. Sample run: Enter the radius of the cylinder: 8.2 Enter the height of the cylinder: 9 The area of the cylinder is 885.75 Question 2 Write a program that reads the name, weight and height of a patient. Then the...
Write a program in python reverse each and every word of the sentence using function taking...
Write a program in python reverse each and every word of the sentence using function taking string as input parameter from user and passing that string into function and also explain the logic ======================================= input: 'Exam is gonna be good' output: 'maxE si annog eb doog' ================ i am trying like this but getting confused '.'join([w::-1] for w in s.split()]) i need more focus on explanations because it is making me confuse i am not clear with concepts so please...
Write a program that asks the user to enter an odd number and prints out a...
Write a program that asks the user to enter an odd number and prints out a triangle pattern. For example, if the user enters 5, the output is note: There is one space between the numbers in each line 1 3 5 1 3 1 If the user enters 9 the output is: 1 3 5 7 9 1 3 5 7 1 3 5 1 3 1 program language: C++
Write a simple TCP program for a client that reads a line of text from its...
Write a simple TCP program for a client that reads a line of text from its standard input (keyboard) and sends the line out its socket to the server. The server reads the line from the socket and prints it in its standard output (screen). The server then reads a line from its standard input (keyboard) and sends it out its socket to the client. When the client sends “!” the server should reply back “bye” to the client and...
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
Write a Python program that splits, doubles, and reverse each input string entered. For each string,...
Write a Python program that splits, doubles, and reverse each input string entered. For each string, split it at the given integer, and then output it in format as shown below. Convert all stings entered to uppercase for output. Assume string length is greater than the split value. Refer to the sample output below. Sample Runs: Enter a string: holiday Enter the number to split on: 3 HOL-YADI-LOH-IDAY Enter a string: TATTARRATTAT Enter the number to split on: 6 TATTAR-TATTAR-RATTAT-RATTAT...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT