Formatting – White Space & Comments
Formatting code generally refers to things that impact how code is displayed but, not how it works. In Python, understanding how white space and comments work is important. Because formatting in Python can actually affect how the code works! White Space In other languages – brackets and parentheses are commonly used to hold or indicate…
Read MorePart 2: Create Job Class
So, we have an account class. Now let’s extend this to a real world example. We want to have a person who has a job and puts money into and out of the bank. First, let’s create a job class. Job Class Attributes Salary or Hourly Weekly salary rate if on salary Hourly rate if…
Read MorePart 1: Create Account Class
Now that you have learned about objects and classes and done some online tutorials – it’s time to create your own class structure and implement this in a program. The steps we will follow are: Define the Class Figure out the main part of the program Write program Test & fix First task Implement a…
Read MoreHomework: Lists
Boring but Useful Homework Create a file called list.py in PythonAnywhere. In this file create the following features: Create a list of what you are going to do this summer. Print out the list Print out the first and third items in your list in a statement like this: “I am going to do _____…
Read MoreFor Loops
for loops are one of the simplest types of loops – it is a loop that will repeat a set number of times. Here is the basic syntax: for index_value in range (start_value, end_value, step_value): # repeat this code until index_value = end_value # can be a single line of code # or multiple lines…
Read MoreUsing Lists
What is in your list? Want to see what’s in a list? The print() function works but is it not really that useful. Why? Because it prints out the whole list including brackets and commas. Useful for debugging but not helpful for a lot of other things. Take a look. Example 1 favorite_numbers = [1,…
Read MoreHomework: Conditionals & Operators
Let’s add on to howold.py. Speaking of – here’s what mine looks like. Compare yours.. #this asks for name & age name = input(“What is your name?”) age = int(input(“How old are you?”)) # calculates age at 2100 age_at_2050 = 2050 – 2020 + age #print using format message = ” You will be {}…
Read MoreConditionals – if Statements
Huh? What is a Conditional? If you have learned another language such as PHP or JavaScript – they are simply if statements. Depending on the condition, an action happens. For example: if it is rainy out, you should take an umbrella. if Statement This compares a condition – if the condition is True – the…
Read MoreLogical Operators
There are several ways to test or compare a variable to a value…or multiple variables to multiple values. Comparisons can be very simple or very complicated. The outcome of both is that we are looking to see if the comparison is valid or True or not valid or False. Logical Operators A condition is how…
Read More