Page 1 of 1

This is one full question. Please write in Python.

Posted: Tue Apr 12, 2022 10:23 am
by answerhappygod
This is one full question. Please write in Python.
This Is One Full Question Please Write In Python 1
This Is One Full Question Please Write In Python 1 (321.71 KiB) Viewed 27 times
2. (6 points) Within ciphers.py, write a function swap(x, i, j) that returns a version of the string x with the characters at indices i and j swapped. If either index is invalid (i.e., something besides 0, 1, 2, ... , len(x) - 1), the function should return None. (To keep things simple here, we'll disregard the fact that Python technically allows negative indices.) The function should work regardless of the order in which i and j are supplied. Do not call any built-in Python functions except len() and range() in your solution. String slicing will be very useful... Here are some example arguments for this function and their expected return values: ។ Arguments ('sloth', 0, 1) ('sloth', 1, 0) ('sloth', 1, 4) ('sloth’, 4, 1) ('sloth’, 4, 4) ('sloth', 4, 5) Return Value 'Isoth' 'lsoth' 'shotl' 'shotl' 'sloth None