Place the following string, list, and tuple:
str = 'Python slicing'
l = ['p', 'y', 't', 'h', 'o', 'n', 's', 'l', 'i', 'c', 'i', 'n', 'g']
t = ('p', 'y', 't', 'h', 'o', 'n', 's', 'l', 'i', 'c', 'i', 'n', 'g')
into your program.
2. Print the string 'Slice' by taking the str string, extracting 'Slic' from str using slicing, and printing the 'Slic' extracted, and the character 'e' after it.
3. Use slicing to get the list ['Si"ng'] from the list l and store the list ['Si"n"g'] in a variable named song. Use slicing to get the tuple ('o', 'n') from the tuple t and store the tuple ('on') in a variable named notOff.
4. Using the input() function, have a user input how many characters they would like to extract. The input the user gives should be an integer, and should be converted using the int() function. After the input has been converted using int(), use the integer to print the following slices:
a) Print a slice starting at the beginning of the str string that has a length equal to the integer from the input.
b) Print a slice starting at the beginning of the l list that has a length equal to the integer from the input.
c) Print a slice starting at the beginning of the t tuple that has a length equal to the integer from the input.
5. Use negative numbers in slicing to print out the following:
a) The last 3 characters of the string str.
b) The last 3 characters of the list l.
c) The last 3 characters of the tuple t.
6. Use a single, negative number step value and perform slicing to print the string str, the list l, and the tuple t backwards.
Program I/O. Input: one number from the console keyboard. Output: Echo the input value and print the result of the calculation to the console screen.
Example. For example, with user input in bold:
Slice How many characters would you like to extract: 3
Pyt ['p', 'y', 't']
ing ['i', 'n', 'g']
gnicilS nohtyP ['g', 'n', 'i', 'c', 'i', 'l', 's', 'n', 'o', 'h', 't', 'y', 'P']
'g', 'n', 'i', 'c', 'i', 'l', 'S', 'n', 'o', 'h', 't', 'y', 'P