86kg to 84kg! Weight lost!

86kg to 84kg! Weight lost!

I’ve lost weight!

This year I weighed around 86kg after putting on weight when my sister left Taiwan. She visited for like a month and during that period I did not exercise. Before my sister arrived in Taiwan, I exercised every single day and sure enough I was doing well. But, boy, when my sister came here she really increased the amount of food I was eating. We would always be eating something and her eating habits slowly drifted onto me. I was begging not go to any buffet restaurants, as I also wanted my sister to lose weight as well.

So, by the time she left I weighed a cool 86kg. I knew I had put on weight and I got myself into gear and restarted my exercising regime the first day she left.

I’ve now cut myself down to just 84kg. It’s been tough as I feel I’ve hit a plateau, but clearly I’m still losing weight and I recently found that out after going in for a check-up to a local hospital. (I’m healthy, thankfully) I’m 183cm and weigh 84.1kg. I’m quite happy with that as I thought the machine would say I was 85kg or more.

As for pictures, I don’t have any at the moment and I don’t feel like taking any; however, I do have an old body shot (of my stomach) and I may put a comparison picture of my progress so far.

Learn Python The Hard Way, Exercise 19

I’ve now moved onto exercise 19.

def cheese_and_crackers(cheese_count, boxes_of_crackers):
	print "You have %d cheeses!" % cheese_count
	print "You have %d boxes of crackers!" % boxes_of_crackers
	print "Man that's enough for a party!"
	print "Get a blanket. \n"

print "We can just give the function numbers directly:"
cheese_and_crackers(20, 30)

print "OR, we can use variables from our script:"
amount_of_cheese = 10
amount_of_crackers = 50 

cheese_and_crackers(amount_of_cheese, amount_of_crackers)

print "We can even do math inside too:"
cheese_and_crackers(10 + 20, 5 + 6)

print "And we can combine the two, variables and math:"
cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)

Explaining each line

Line 1

On line 1 we have the start of the mini-script (“def”) and then we have cheese_and_crackers which is the function that will be used throughout the rest of the script. For this first function/mini-script we have “cheese_count” and “boxes_of_crackers”) inside the parenthesis. We’ll use these on lines 2 and 3.

Lines 2 – 8

On line 2 we have %d that uses “% cheese_count” and that “name” is on line 1; the same goes with line 2. The other lines are too basic to explain, so I’m just going to skip to line 8, which is where the data is pulled when executing/running the file, so that line 8 “cheese_and_crackers(20, 30)” with the numbers corresponding and displaying when the file is executed.

Lines 10 – 14

The more direct way of imputing numbers is using variables and in this case we declare the numbers after creating a variable name then after the equation mark we enter the value (Lines 11 – 12).  So we can re-use the function data from “cheese_and_crackers” we use it when  calling for the variables so it re-uses the data in lines 1 – 3; however, uses the values within the variables and not the values in line 8.

After explaining all those lines, the rest of the lines make sense now and I feel I have a clear grasp of it now.

Output in Windows Powershell:

We can just give the function numbers directly:
You have 20 cheeses!
You have 30 boxes of crackers!
Man that's enough for a party!
Get a blanket.

OR, we can use variables from our script:
You have 10 cheeses!
You have 50 boxes of crackers!
Man that's enough for a party!
Get a blanket.

We can even do math inside too:
You have 30 cheeses!
You have 11 boxes of crackers!
Man that's enough for a party!
Get a blanket.

And we can combine the two, variables and math:
You have 110 cheeses!
You have 1050 boxes of crackers!
Man that's enough for a party!
Get a blanket.

Next step

So, after learning and studying this, I moved onto the next step. The next step was creating something of my own and seeing if it would work. Since I like the raw_input() function, as you can add user input functionality, I tried and succeeded in adapting raw_input() with a def function.

Here’s what I got:

def hello_world(name, country, favcountry, favgame, languages):
	print "\n"
	print "This is how you responded to those questions:\n"
	print "Your first name is: %r" % (name) 
	print "Your country of origin is: %r" % (country)
	print "Your favourite country is: %r" % (favcountry)
	print "Your favourite game is: %r" % (favgame)
	print "You said you can speak these languages: %r" % (languages) 
	print "That's all! \n"

print "Please answer the following questions." 
hello_world(raw_input("First name: "), 
raw_input("Your country of origin: "), 
raw_input("What's favourite country?: "), 
raw_input("What's favourite game?: "), 
raw_input("What languages can you speak? (Separate with a comma): ")
)

It works and it isn’t too shabby. However, according to this exercise I have to use 10 other functions in the same file to show that I really know how to use this newly learnt method and probably to practice other functions other than those I’ve been using for a long time! I’ve only used one type of function which is raw_input(); however, I’m a little tired of this exercise so I’m going to move onto exercise 20 and I’ll return to this exercise, if need be it!

Learn Python The Hard Way, exercise 18

I found this exercise to be quite comforting; however, at first I was a little confused when presented with all that new code that I had never seen before. In this exercise it teaches you about the “def” (Define) and creating functions (Mini-scripts).

To overcome my confusion, I typed the whole thing out and ran it in Windows Powershell. Then for extra practice I created another file and typed each function one by one and changed those functions to get an idea on what each and every thing does.

Here’s my code:

# FUNCTION 1
def print_two(*args):
	arg1, arg2, arg3 = args
	print "arg1: %r, arg2: %r, arg3: %r" % (arg1, arg2, arg3)

print_two("Hello","Mr","Python")

# FUNCTION 2
def print_two_again(arg1, arg2): 
	print "arg1: %r, arg2: %r" % (arg1, arg2)

print_two_again("Hello2","World!")

# FUNCTION 3
def print_none():
	print "Nothing here."
print_none()

I only modified it slightly, for testing purposes, and then tested each and everyone of them. It’s quite fascinating how it works and it has got me more interested in learning as it’s a really simple way of explaining these various different methods of displaying data in Python.

Instead of using argv or variables to display strings, you can simply create functions which, I guess, organises the code; I suspect.

Learn Python The Hard Way, Exercise 17

I’m currently working/studying exercise 17 from Learn Python the Hard Way. In this exercise I learned two new things, and those two reasons are why I created this new category which will cater for my programming experiences, as opposed to me creating hundreds of pages and having my navigation bar up-top filled with drop down menus on the “code” navigation link.

As for my programming abilities so far, I’ve been typing out every single piece of code in this eBook by hand (As requested by the author) with no copy and pasting whatsoever! I’m quite proud of that actually.

Anyways, in the exercise it states that I need to condense the following code:

from sys import argv
from os.path import exists

script, from_file, to_file = argv

print "Copying from %s to %s" % (from_file, to_file)

# we could do these two on one line too, how?
in_file = open(from_file)
indata = in_file.read()

print "The input file is %d bytes long" % len(indata) 

print "Does the output file exist? %r" % exists(to_file)
print "Ready, hit RETURN to continue, CTRL-C to abort."
raw_input()

out_file = open(to_file, 'w')
out_file.write(indata)

print "Alright, all done."

out_file.close()

To this:

from sys import argv; from os.path import exists; script, from_file, to_file = argv; print "Copying from %s to %s" % (from_file, to_file); in_file = open(from_file).read(); print "The input file is %d bytes long" % len(in_file); print "Does the output file exist? %r" % exists(to_file); print "Ready, hit RETURN to continue, CTRL-C to abort."; raw_input(); out_file = open(to_file, 'w').write(in_file); print "Alright, all done."

# we could do these two on one line too, how?
# indata = in_file.read()
# out_file.write(in_file)
# out_file.close()
# in_file.close()

As you can see I condensed the code to just one line with semi-colons, and I hashed out the code that wasn’t needed for the operation that the code is to do. It still works and copies from one file to the other.

I got rid of close() as I’m still not sure yet what purpose that serves in relation to this, though I’m assuming I can just add this to the end; though it’s throwing up errors. I’m just looking to progress onward and if I run into an issue like that I’ll have a sit down and think about solving it or asking on websites designed for these types of issues.

I also combined from the original code in line 18 and 19 to this:

out_file = open(to_file, ‘w’).write(in_file)

Not sure if that is correct; however, the script is still functioning and does its’ job.

I’m sure if an expert Python programmer came and saw this they would faint, but I’m still trying to learn and I know I have a long road ahead of me.

 New Parameters & Formatters

import  exists – This will confirm whether a file exists or not. If a file exists it will report back with True, if the file doesn’t exist it will report back with False. In Windows Powershell, it outputs the following:

Does the out-put file exist? True 

len() – (length) This will measure the length of a file. In the above example the output in Windows Powershell is:

The input file is 686 bytes long

Weight loss journey from 2010 – 2013

Weight loss journey from 2010 – 2013

Broken leg

This is when I broke my leg at the age of 16.

Losing weight has always been something that I’ve wanted to do, but that I’ve never done until recent. I didn’t use to be overweight (I’m not overweight now – as I write this) and at one point I could run for as long as I wanted and was one of the best long distance runners in my school year at secondary school. (See picture to the right; you can see that I wasn’t overweight at all.)

That is of course until I broke my leg playing football. I missed 6 months of school that I could never recover and if I was ever behind in any subject at school, it was at that point where I was doing my worst. I started putting on weight, as I could not exercise for over a year and a half, and I had not bothered to watch my weight. Life was on the downside and I piled on the stones/pounds like a baby elephant.

My leg injury, which damaged my growth plate, has still left its everlasting mark on me and has caused me to have issues like early symptoms of arthritis, it has affected me in more ways than I could have imagined. However, I’m committed to doing what I’ve always wanted to be, a fit and healthy person. I plan to complete marathons and I plan to become a healthier me.

I could ramble on and on, but that would be quite boring. To say as little as I can, I put on weight and managed to top weights of around 110kg, which is around 17 stones, 244lbs or 0.111 metric tonnes. 😛 I was a heavy motherfucker.  (more…)