At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
>>> prefixes=('JKLMNOPQ') >>> suffix=('ack') >>> for letter in prefixes: print (letter + suffix) Jack Kack Lack Mack Nack Oack Pack Qack >>> #The question they are asking is how to modify this program for the prefixes so that 'u' would be added in between 'O' and 'ack' and 'Q' and 'ack' to create Ouack and Quack. Please help me. Thanks!!
Do you understand this program as it is ?
Ahhh.. I think I do, but I can I ask some dumb questions just in case?
ahhh, so the word letter does not matter at all does it? its just used to understand that we're taking a letter but it could be any other word right?
letter is character, you can add more than 1 character
?? so the word letter does have a significance?
Before starting to code, try to imagine in your own words what you want to do. I would say, for this problem: for each prefix, I want to append the suffix. If the prefix is 'O' or 'Q', I also want to add 'u' between the prefix and the suffix. If you read that carefully, you will see that the code is mostly done.
prefixes, suffixe, letter are simply variable names. They could have been named foo, bar and maitre_kaio, doesn't matter for the interpreter. But it DOES matter for us, humans, because good variable names help us to understand the code.
ok! thanks! that clears that question up. so, how exactly does for work??
just by saying for it takes each letter? is that the function? is that the only function it has? Can it be used in a different way then "for letter in prefixes:"?
yamaka, I don't want to be rude but have you read anything about the basic structures of Python ? If not, please check that one: http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_2.6 Because you probably understand that we can't write a full Python tutorial here. If you have already read some references, please ask more accurately what you don't understand
I'm sorry, I read the text book and how it's supposed to work, but it just doesn't seem to be clicking for this 'for' concept.
OK, imagine you have a collection of elements. They may be of any type (integers, float, string, ....). You want to do something with each of them. Or should I say: for each element in set: do something
ohh!!! ok that makes sense, so that's why it say 'for letter in prefixes:' ok i got that now!! Thank you!
what book are you following, it should be written there about it
I'm following the "How to think like a computer scientist", but it says it in such a way that i didn't get the part about elements...probably just lack of understanding on my part tho X(
you may try look at this book http://bit.ly/bzodNl i haven't read it but it looks promising :D
Thank you Tomas XD