Python: The First Chapter

*NOTICE Code Snippets cannot be seen on WordPress Reader, must be viewed on original site


First off, it was stressed that the point of this class was first and foremost Programming Fundamentals, not becoming Python experts. I loved this approach personally, and it’s not like we are not learning a ton of syntax and logic going through the motions anyhow. Our first file was a simple one (this was of course after the initial Hello World start which can be as a simple print statement, i.e., print(‘Hello, world!’)), ask a user for their last name.

# Asks for user's last name.

name = input('Last name: ')

print('Last name is:', name)

My takeaway from this a few things: what the hell is a variable, that must be a statement that displays something, yay it worked, and that calls the variable like that after storing some input, hmm, sweet, a lot going on there from a beginners perspective, but cool!

Afterwards, we went through quite a few whiteboard exercises and flowcharting. Picked up a version of Microsoft’s Visio (thank you student perks and discounts!) to do the diagrams.

This slideshow requires JavaScript.

It helps! Being able to structure out your program before writing any code logically seems like a no-brainer, but sometimes people take planning for granted. Then just jump right into barreling through the design process before attempting to find pitfalls ahead of time.

The next thing we went through was a program that follows one of the flowcharts we made for tip, tax, and charge. Played with different errors to get used to seeing them and went ahead and practiced some more equations, as well.

# Tip, Tax Food Calculator
# First Flowchart problem homework 1

# We will use 18% as the tip rate

# Currently the tax rate is 9%

charge_for_food = float(input('Input charge for food: '))

tip = TIP_PERCENTAGE * charge_for_food
tax = TAX_PERCENTAGE * charge_for_food
total = charge_for_food + tip + tax
# + tip + tax works and is a LOGIC error, will still run without syntax issues.

#Leaving off the f on .2f will make numbers go into exponential notation
print('Charge for food: $', format(charge_for_food, ',.2f'), sep = '')
print('Tip: $', format(tip, ',.2f'), sep = '') 
print('Tax: $', format(tax, ',.2f'), sep = '')
print('Total: $', format(total, ',.2f'), sep = '')

Learning how to comment a program you are writing, I think, is an essential skill for future proofing what you’re doing. I’ve already gone back just a couple months and have forgotten just what I was trying to attempt and had to relearn my logic or algorithm just to be able to edit it properly. Obviously, this will get easier with time, but proper commenting has been a lifesaver. Comment!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s