Computer Science
Write a program which reverses a string and stores the reversed string in a new string.
Python
Python String Manipulation
39 Likes
Answer
str = input("Enter the string: ")
newStr = ""
for ch in str :
newStr = ch + newStr
print(newStr)
Output
Enter the string: computer studies
seiduts retupmoc
Answered By
21 Likes
Related Questions
Write a program to count the number of times a character occurs in the given string.
Write a program which replaces all vowels in the string with '*'.
Write a program that prompts for a phone number of 10 digits and two dashes, with dashes after the area code and the next three numbers. For example, 017-555-1212 is a legal input. Display if the phone number entered is valid format or not and display if the phone number is valid or not (i.e., contains just the digits and dash at specific places.)
Write a program that should do the following :
- prompt the user for a string
- extract all the digits from the string
- If there are digits:
- sum the collected digits together
- print out the original string, the digits, the sum of the digits
- If there are no digits:
- print the original string and a message "has no digits"
Sample
- given the input : abc123
prints abc123 has the digits 123 which sum to 6 - given the input : abcd
prints abcd has no digits