Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Wednesday, July 17, 2013

To ARGV or to To Variable, is it really a question?

Ok, so it's not the best title ever, considering, but what the heck.

So still working through the Python lessons. So far it doesn't seem too different from what I used to do with a shell/bash script ( I inherited some and learned what they did. Then created some new ones based on them). Though the 'language' does seem to be a bit easier, and I see how it might be easier to accomplish some things better.

That being said, most of the lessons so far, are calling for argv values, for lack of a better term. With this you call the script with arguments after the file name:

ex17.py old.txt new.txt

ex17

theirs

So that does seem to work, so long as the person who calls the script knows what they are supposed to do.

Personally I prefer something more like this:

ex17a

mine


Yes it is more lines of code, but to me at least, it seems more user-friendly. I could have anyone call my script and it asks them for the file names vs expecting them to know what they are supposed to do.

Monday, July 8, 2013

Python Day 1

So trying to learn some python. I had a couple of people recommend this course.

So I started to run through it on Friday. First two lessons were not that bad. Basic "print" statements to start followed by "comments/#" usage.

So far so good right? In comes lesson three, math with python. Most of the basic functions were easy to pick up. Multiplication, division, addition, subtraction and of course the proper order of operations. It also goes into > greater than, >= greater than or equal to, < less than, <= less than or equal to, and finally % percentage/remainder. Or at least I think it's supposed to be remainder.

It is this final piece that has been kicking my butt. So I get that the modulus (%) is for remainder, I can't figure out how it works.
The formula for the exercise is " 100 - 25 * 3 % 4" the answer is 97.

So I'm still trying to figure out how this works before I move on. Of any of you out there can point out a good explanation feel free to let me know.

Or once I figure it out I'll update.

 

Update

 

Ok, so with the help of a coworker it looks like I've figured this out.  So the "%" means divide by following number, but use the remainder for the next piece of the equation.

So what that means for the above equation:

100 - 25 * 3 % 4

100 - 75 % 4 ( which means 75 / 4 which is 18.75, but not using floating points yet, so it's 18 remainder of 3)

100 - 3

97

 

And I'm sure my Algebra I teacher would be happy I showed my work...