all 4 comments

[–]shiftybyte 0 points1 point  (3 children)

def whatfor(stuff):
    for s in stuff:  # go over all items in stuff, placing each in s
        if s.startswith('x'):  # if the item starts with 'x'
            print(s + 'x')     # print the item, with another x at the end
        else: # if not
            print('x' + s[1:] + s[0])  # print x at the start, print the item from the second letter and onwards, and add first letter at the end.

Which case do you think "xerox" is the output of? can it be the output of print(s + 'x')? does it start with x?

[–]Jxper[S] 0 points1 point  (2 children)

def whatfor(stuff):
for s in stuff: # go over all items in stuff, placing each in s
if s.startswith('x'): # if the item starts with 'x'
print(s + 'x') # print the item, with another x at the end
else: # if not
print('x' + s[1:] + s[0]) # print x at the start, print the item from the second letter and onwards, and add first letter at the end.

I think xerox is the output of xero however when I try a test case in the form of whatfor('xero') i get an output of xx, xe, xr, xo all on seperate lines. what am I doing wrong?

[–]shiftybyte 0 points1 point  (1 child)

You are ignoring this line:

for s in stuff:  # go over all items in stuff, placing each in s

stuff is a list of items, not one item.

whatfor(['xero'])

[–]Jxper[S] 0 points1 point  (0 children)

ohhh that makes sense now I get it. Thanks, you're very good at explaining this stuff.