Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CMPT 120 - Assignment 1

Problem Statement

Recall that a string is palindrome if it reads the same forward and backward. Given a string that contains only lower-case English alphabets, you are required to create a new palindrome string from the given string            following the rules gives below:

1.   You can reduce (but not increase) any character in a string by one; for example, you can reduce the character h to g but you cannot increase from g to h

2.   In order to achieve your goal, if you have to then you can reduce a character of a string repeatedly until it becomes the letter a; but once it becomes a, you cannot reduce it any further.

Each reduction operation of a character is counted as one. So you need to count as well how many reductions you make.

Write a Python program that reads a string from a user input creates a palindrome string from the given string with the minimum possible number of operations and then prints the palindrome string created and the           number of operations needed to create the new palindrome string.

Input Format

Your program must take one string input from the user. You can assume the user will always enter a string       made up of only lower-case English alphabets (no spaces, no punctuation marks, no upper case letters, and no other symbols). Therefore, your program should start as follows

Please enter a string input: _______________ 

Where the ________ means the user will enter input to your program.

Output Format

The output of your program must be as follows:

The palindrome string created is: _______________________

Number of operations required is: ______________________

Where the ________ means you will print the palindrome string created and the number of operations.

Submission Format

You are required to submit your program online through Moodle. You will find a submission button for    Assignment 1 on Moodle and you are required to upload your program written as Python Script (with file name AnyfileNameYouChoose.py) there.

Marking

A nonworking program will automatically get zero. A program that works but doesn't give right output or gives partial right output will lose marks depending how severe its shortcoming is.

Sample Examples to test your program

In order for you to test your program for some possible inputs, I have prepared a list of example inputs and outputs that you can test your program with:

Input String                                               Palindrome String Created         Number of Operations

1.                                                                                              0

2. g                                           g                                               0

3. abcba                                       abcba                                           0

4. cba                                         aba                                             2

5. abcd                                        abba                                            4

6. cmpt                                        cmmc                                            20

7. tstniebbfgsaoejunprxxezeg                  geteiebbfgjaoajgfbbeieteg                      141

8. zgxpmbsdxjtttjtzkoljeqvayqurddzuksdgavpd  dgvagbsdujddrjqyaoleeloayqjrddjudsbgavgd      158

9. ufwoijxykbhmvzheketqpzvxrdruhhctsoxgauvb  bfuagjoskbhhurdeketpptekedruhhbksojgaufb      160

10.ebdsqgrlxofhtlptamoibdfxzaxunmjmqyqmipql  ebdimgrlmjfhtlatafdbbdfatalthfjmlrgmidbe      181