Good morning Internet/Blog viewers,
I'm currently using the website Code Academy to teach myself how to program in Python.
If you read my previous post i mentioned that i was doing this to kill some time however, that is not the only reason.
It was suggested to me in my 3rd year of university by one of my tutors that i learn a bit of Python since we were using it in a forensics exercise. For reasons that baffle even myself, i was remarkably hostile to this idea and rejected the suggestion. However it has come to my way of reasoning that as technology progresses, so does the need to learn to program as life is currently littered with App's and Programs.
You use your phone, the text messaging is an App, almost all the functions on your phone are based off applications and the same can be said for computers which brings us full circle as to why i'm learning to program. Its necessary for the progression of my technological skills.
So, onto my first few lessons on Code Academy, The first few lessons have taught me about commenting, proper indentation (which is key!) and variables.
See below for the basics
The code from above is:
# Assign the variable total on line 8!
meal = 44.50
tax = 0.0675
tip = 0.15
meal = meal + meal * tax
total = meal + meal * tip
print("%.2f" % total)
The # is for commenting, according to my friend, its good practice to comment your code so its clear and easy to read, generally the comments state what that section of code is supposed to do. (Sorry if this is super basic, this is where i'm learning from!)
Line 2 shows meal which is the variable, the = is to show what the variable is going to be, the 44.50 is the actual variable.
You have to assign each variable its own thing otherwise it won't work, so when we skip down to line 8, we see that to add up, we can use the variable names and the command on line 10 (code academy added it), prints your code into a tip calculator!
Hopefully if your reading this and also a beginner, my post has been sort of useful. Good Luck!
No comments:
Post a Comment