Solving Problems …..

I’ve been working on solving Python problems and some are really starting to come naturally (HOORAY!). There were a few that I had to cheat and look up how to solve them, but most them I was able to figure out on my own (again, HOORAY!). All of the ones I’m showing you today are all problems that have taught me at least one thing. I’ll show you the screenshot and list my big takeaway 🙂

front_9

For this, I learned how to look in only the front 4 numbers of a given list. I learned how to use the

end = len(nums)

if end >4:

end = 4

which helped me look in only the front 4 numbers. Then use the range(end) and if nums[i] == 9 to see if any of those numbers were a 9.

string_splosion

This one was weird and I didn’t really see what they were doing at first. I finally had to cheat and figured out what they were asking afterwords. Add string[0]+string[0:1]+string[0:2]…etc. to an empty string until there was nothing left to add. Had to use the range method and then result += str[:i+1] which I had to study for a while before I realized that it was the same as what I posted above.

last_2

This one was weird. But I learned how to look through groups of 2 letters for something that matched the last 2 letters and count how many times that happened. Had to say what the last 2 were first, then look through the rest of the letters two at a time (str[i:i+2]) to see if that equaled the last2. If it did, add 1 to the count.

every_other_char

This one I solved on my own. That one problem where I had to capitalize every other letter actually helped me with this one.

missing_char

This was tougher than it first looked. The front section was all the letters up to (but not including) whatever the n index was. the back section was rest of the letters, starting after the n index (str[n+1:]). Then you just had to put the front and back together.

front_back

I figured this one out after cheating on the last one. The part that almost tricked me was how do you know what index the last letter is??? Then I remembered [:-1] does the trick!

 

 

So there’s a bunch of stuff I learned this weekend. Hope you enjoyed 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s