Tag Archives: Udacity

Udacity CS101 – Rounding without if statements hurt my brain


This picture of a baby beaver is unrelated to anything, but I love it so much that I don’t want to forget it existed

We have completed week 1 of the Udacity course, and although I don’t know what is coming in the rest of the course, Udacity seems a lot more like Lynda/Codecademy/Code School/Treehouse than the CS101 Stanford course I did on Coursera. The Stanford course mixed in coding with some computer principles, like bits/bytes, what the parts of a computer are, how everything in a computer boils down to a number, etc. I’m not sure if Udacity will go there at some point, but doesn’t seem so yet.

Having said that, the course is much more modern from a users perspective, it’s a lot more ‘meaty’ (lectures are longer) and as a user you do more work/tasks/quizzes.

So I guess, if anyone asked me which I would recommend, I would have to be lame and say both, because I think they offer really different (and valuable)things.

Below are just a few of the interesting things I’ve learnt or figured out so far in the Udacity course:

How to make a decimal round up or down without an if statement

Note that this hurt my brain. A Lot.

– Add 0.5 to your number

i. If it is less than 0.5, then the whole number will remain the same

ii.If it is 0.5 or greater, then the whole number will increment one

- Make the number a string

- Find the decimal in the string with the find method

- Print the string up to the position of the decimal.

How to check if a string is a palindrome

Treat as an array

- Find the length of the array and divide by 2. This is the halfway mark.

- Use this function of an array[::-1] to read the string backwards

- Look for the first half of the array (up to midpoint) reading the array backwards

If it is a palindrome, that first half string will be found at position 0 from the end.

If it isn’t, the result will be that it can’t find it, and it will return -1

The Most Basic Principle of Writing a Method/Function

This next one is obvious, but was never verbalised to me. I think it will come in useful to get things back to basics, if I struggle writing a function in the future.

To write a method or function, you need to first know

i.What do you want to come out of it at the end? (i.e. what should it return)

ii. What do you need to put into it (i.e. variables)

If you know these two things, you can more easily write the method. (I hope you didn’t just think ‘der’)

Well that’s it for now

Leave a reply