print(‘print each letter at a time’) while place[counter:]: print(place[counter]) counter+=1
hospital has 8 letters
print each letter at a time h o s p i t a l
This is created by a nested while loop. Each loop starts at 0 and increments to the length of hospital. When outside loop increments it seeds the number for the inside loop to begin with. i must be less than j. If i=j, it will print a blank line.
print(‘slicing strings’) i=0 while i <= length: j=i while j <= length: print(place[i:j]) j+=1 i+=1 print(”);
slicing strings
h ho hos hosp hospi hospit hospita hospital
o os osp ospi ospit ospita ospital
s sp spi spit spita spital
p pi pit pita pital
i it ita ital
t ta tal
a al
l
I added if i not equal to j, to not print the blank. I added the print(i, ‘ ‘j) to show you what prints at each increment.
i=0 while i <= length: j=i while j <= length: if i!=j: print(i,’ ‘,j) print(place[i:j]) else: print(i,’ ‘,j) print(”) j+=1 i+=1 print(”);
0 0 #prints nothing
0 1 h 0 2 ho 0 3 hos 0 4 hosp 0 5 hospi 0 6 hospit 0 7 hospita 0 8 hospital