Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+1 vote

I do not understand how we are supposed to determine flen and slen on a word by word case. For example: how does python know that it has to use 4 letters for flen and 6 letters for slen instead of 5 letters for the example: combine('stay', 4, 'vacation', 6) staycation. I know that they both cannot be longer than first and second but I do not understand which specific letter it stops on.

asked in CSC201 by (325 points)

1 Answer

+1 vote

The combine method is receiving 4 values as parameters which the method description is naming first, flen, second, slen. In the example you mention,
first is assigned 'stay'
flen is assigned 4
second is assigned 'vacation'
slen is assigned 6

I would think about using slicing to slice the letters you want from the given word. Typically with slicing, we've used literals (like 4), but variables can be used too.

For example, first[:4] would return 'stay', the letters in first from index 0 up to, but not including the letter at index 4. Instead of 4, I could use first[:flen] and it would do the same thing. If instead flen was assigned 3, then first[:flen] would return 'sta' instead.

answered by (4.3k points)
...