I'm new to python and I am currently working on a exercise that involves slicing. The exercise involves slicing the string 'Pizza' in any way. You enter the starting and ending positions of the slice and the program displays the results. Here is my code:
#Pizza Slicer
print(
"""
Slicing 'Cheat Sheet'
0 1 2 3 4 5
+---+---+---+---+---+
| p | i | z | z | a |
+---+---+---+---+---+
-5 -4 -3 -2 -1
"""
)
word="pizza"
print("Enter the beginning and ending index for your slice of 'pizza'.")
print("Press the enter key at 'Begin' to exit.")
start=None #initialise
while start !="":
start=int(input("\nStart: "))
if start:
finish=int(input("Finish: "))
print("word[",start,":",finish,"] is", word[start:finish])
The issue is that when I enter a starting value of '0' I cannot enter a finishing value - 'Start:' appears again. I think this may have something to do with the 'Start = None' statement. The other issue is that entering negative starting and ending values does not work and will not return the slice. Not sure why.
Thanks for your assistance.