With the comments on the same line as the code, it refers to. e.g
NumBob = 0
s = 'sexbobombob'
i = range(len(s)+1) #Generates a list from 0 to the length of s
u = 0 # This would be the variable storing each value of the list
for ans in i: # this allows me to extract each value of i
if ans > 0: # Completely arbitrary. i just used any condition that allows me to pick up all values in the list.
u = ans
x = s[u:u+3] #By using indexing to pick u, u+1, and u +2 i can pick up 3 letters at a time
if "bob" in x: # Checking if the term i picked up is a Bob
numBob += 1 # increasing the Bob count
print "Number of times bob occurs is:" + str(numBob) # Printing the number of Bobs
With the comments beneath the line of code, it refers to. e.g
numBob = 0
s = 'sexbobombob'
i = range(len(s)+1)
#Generates a list from 0 to the length of s
u = 0
# This would be the variable storing each value of the list
for ans in i:
# this allows me to extract each value of i
if ans > 0:
# Completely arbitrary. i just used any condition that allows me to pick up all values in the list.
u = ans
x = s[u:u+3]
#By using indexing to pick u, u+1, and u +2 i can pick up 3 letters at a time
if "bob" in x:
# Checking if the term i picked up is a Bob
numBob += 1
# increasing the Bob count
print "Number of times bob occurs is:" + str(numBob)
#Printing the number of Bobs
Or with the comments preceding the line of code. e.g
numBob = 0
s = 'sexbobombob'
#Generates a list from 0 to the length of s
i = range(len(s)+1)
# This would be the variable storing each value of the list
u = 0
# this allows me to extract each value of i
for ans in i:
# Completely arbitrary. i just used any condition that allows me to pick up all values in the list.
if ans > 0:
u = ans
# By using indexing to pick u, u+1, and u +2 i can pick up 3 letters at a time
x = s[u:u+3]
# Checking if the term i picked up is a Bob
if "bob" in x:
# increasing the Bob count
numBob += 1
# Printing the number of Bobs
print "Number of times bob occurs is:" + str(numBob)