In python: Write a function stringRev() which will ask the user to input a strin
ID: 3668316 • Letter: I
Question
In python:
Write a function stringRev() which will ask the user to input a string and the number of characters they want to move from the front of the string to the back of the string. When the user enters the number 6 for the string, the function completes. If the user enters a number of characters to move that is 0 or less or is greater or equal to the string length, an error message will be printed. When the user enters a string and an appropriate number of characters, the function will create a new string with the first n characters in the string removed from the front and concatenated to the back of the string. This new string will then be written to an outfile called stringRev.txt so that each string and number pair that was correctly entered will have the resulting new string written to a single line in the file.
>>>stringRev ) enter string or 6' if finished: abcd enter number f characters t move to back f string : -1 abcd:-1 characters cannot be moved. Please try again. enter string or 6' if finished ahhhhhhh enter number of characters to move to back of string: 0 ahhhhhhh: 0 characters cannot be moved. Please try again enter string or 6' if finished: pineapple enter number of characters to move to back of string: 4 enter string or '6' if finished: three enter number of characters to move to back of string: 3 enter string or 6' if finished: abcd enter number of characters to move to back of string: 9 abcd: 9 characters cannot be moved. Please try again enter string or 6' if finished: 6 You are done. stringRev.txt file looks like stringRev - Notepad File Edit Format View Help applepine eethrExplanation / Answer
#include #include int main() { char one[200] = "madam"; char two[200]; strcpy(two, one); strrev(two); if(strcmp(one, two) == 0) printf("The entered string %s is a palindrome. ", one); else printf("The entered string %s is not a palindrome. ", one); printf("The reverse of the string is %s. ", two); return 0; } #include #include void reverse(char s[]) { int c, i , j; for (i = 0, j = strlen(s)-1; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.