Zarilenth the Completionist

  • Archive
  • RSS
  • Ask
  • Submit

Learning Python the Hard Way: Variables and Names

Exercise 4

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.

    • #Programming
    • #Python
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Learning Python the Hard Way: Numbers and Math

Exercise 3

This chapter covers basic mathematics operators, and already I can see how these can be used in many different situations. The only point of confusion I had with this lesson was with the “%” symbol. I thought it had something to do with percentages or decimal places, but couldn’t get my answer to come out right. 

After, some research in the comments and on Wikipedia, and after brushing up on my long-division, I can now understand modular arithmetic. If that’s not extra credit, I don’t know what is.

1. Commenting makes a lot of sense to keep everything in order. I will try to keep this in mind and comment often.

2. Pretty useful for basic operations, and unlike the calculator I can open, it’s much easier to use parentheses and order of operations.

3. I wrote a little program to calculate how far $20 in bus fare will get me each week, assuming I’m adding in a dollar each day from tips.

4. A floating point is just the inclusion of a decimal place for accuracy. I rememeber this from C++.

5. Done. There’s no loss of accuracy anyway, but the author is really great at making you do redundant tasks to reinforce a good foundation.

    • #Programming
    • #Python
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Learning Python the Hard Way: Comments and Pound Characters

Exercise 2

I guessed correctly in my last post when I assumed pound characters were used for commenting or disabling a part of my code. There’s not much else to say for this lesson, so onward to extra credit section.

1. Yes, I was right.

2. I am assuming this is just an exercise in proof-reading and looking at things with fresh eyes.

3. I found an extra colon. Doctor?

4. I didn’t find any more mistakes, perhaps “python” should be capitalized. I get it though, you can’t proof-read enough.

    • #Programming
    • #Python
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Learning Python the Hard Way: A Good First Program

Exercise 1

Now that we have the basics out of the way, we can learn to program. I already have a small amount of experience with C++ and ActionScript, so I am sure that I will blow right through the first couple of lessons. Displaying text using the print command is straightforward enough and that’s as in-depth as this lesson goes. 

I really like the idea of trying to use the concepts I have been taught before moving on, so the extra credit section at the end of each chapter seems like a great way to do that.

1. I would just add print “Whatever text I wanted here,” on another line.

2. Based of the next question, I could add an octothorpe or just delete all but one of the lines.

3. Taking into account the small knowledge I have of programming, I can tell that an octothrope is used for commenting.

    • #Programming
    • #Python
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Learning Python the Hard Way: The Setup

Exercise 0

Rather than being a full-fledged exercise, this chapter merely goes over prerequisites for the upcoming chapter. You need to install gedit, a text editor, Python (I’m using 2.7.2, the book teaches Python 2 and not Python 3), and be familiar with either the terminal or command prompt within your OS.

I had no previous experience with using a command prompt, so I searched up a quick crash course and within minutes I had Python installed and could create and move directories.

    • #Programming
    • #Python
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Learning Python the Hard Way: The Hard Way is Easier

Introduction

Learn Python the Hard Way by Zed A. Shaw

I posted on reddit a little while ago asking what some good books to get into programming were. Thank you MindOfJay for recommending what looks like a great one. Sticking with a theme of self-improvement, I am going to track my progress learning Python via posts for each lesson here.

    • #Programming
    • #Python
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

About

Avatar Forsooth!

Following

  • thedrunkenmoogle
  • humblebundle
  • staff
  • notch
  • gamingcompletionist
  • origombie

Top

  • RSS
  • Random
  • Archive
  • Ask
  • Submit
  • Mobile
Effector Theme by Pixel Union