October 15, 2014

Week of 10/12/14 - Python Part 06: Breakthroughs

    While last week I was having some problems with figuring out how to determine if a number is prime using a brute-force method, this week I was able to do so without too much issue. One of the problems was that if I divided the number by another number in between 2 and itself, and it's remainder was zero, I would evaluate the function as true, that it was prime, even though that is the opposite of what it means to be a prime number. I fixed that by evaluating that as false, and then made an else statement that would evaluate as true once it exhausted the list between 2 and the number. Then I tested it using the prime number 104,729, which is the ten-thousandth prime number, and the function evaluated as true. And 104,727 evaluated as false. Very nice. Next, what the Codeacademy asked me to do was take an input string and reverse it. I started out by adding the last letter to the end of the original string, then deleting the last letter. The problem with this is that it causes an infinite loop and causes the string to come out as "stringgggggggggggggggg". I decided to just append each letter in backwards order in a new list, and then returned the list with no spaces between the letters.

No comments: