Learning Python the Hard Way: Variables and Names
Finally getting into naming and variables and I feel like I can do something with Python now. I found this exercise to be very useful, and not just because of the content, but because it pushed me to think beyond what was on the page.
I already knew that you could assign a variable to a number, e.g. cars = 100 or drivers = 30, but I never realized that you could create a new variable as a result of two others, e.g. cars_not_driven = cars - drivers. I find this really fascinating, and while answering the extra-credit questions kept thinking of a ton of new uses for this.
As for the error before the extra credit questions, the variable car_pool_capacity is never defined. The variable carpool_capacity, so a simple typo.
1. This question drove me insane for a good two hours. There is no actual reason to use a floating in this example. The author actually states in the comments that it was merely for practice and just to get you thinking. I did get some experience posting to stack overflow, however.
2. Yes, I believe I know what a floating-point is.
3. More commenting.
4. An equal signs for assignment, got it.
5. Underscore character? Psh, I’m from the internet.
6. I never realized that Python can be used on the fly like this. I still prefer to save a .py file and run it.