Search
  • Kaitlyn Flowers

Python Class, Week 2!

Here's the review of our second class. The class powerpoint is linked below:

Week 2 Python Class
.pdf
Download PDF • 113KB

Some more Basics:


In Python we use these math operators for simple equations.

Addition: +

Subtraction: -

Multiplication: *

Division: /

Exponents **




We also use these comparison Operators to compare different objects:

Equal: ==

Not Equal: !=

Greater than/lesser than: < or >

Greater/Lesser than or equal to: <= or >=



Here are Python's basic data types:

Integer/whole number: int

String (text): str

Float (decimal number): float

Boolean (true/false): bool






Lists:

  • A list is a data structure that allows us to group data together and assign them to a variable.

  • In other programming languages such as Java, a list is known as an array

  • We use square brackets ('[' and ']') to define a list, and separate the elements or items in our list using commas.

names = ["Rachael", "Mana", "Minseo"]

We can enter any type of data in our list:

example_list = [42, "hello, world!", 3.0, True]

...and we can print a list like this:

print(names)
print(example_list)

Accessing Items in a List:

- lists use an index to refer to a specific position of time

- Index starts at 0, so the index of the last item will be 1 less than the total number of items in your list

- To access an element of a list using index, we write: list[index]

names[2] #This should print 'Minseo'
example_list[0] #This should print 42

Looping through a List:

Programmers often use for-loops and while loops with lists. You can iterate (go over the range of items in a list and perform the same task) through the list using these loops. Let's take a look at an example:

scores = [96, 93, 84, 90, 98, 81]
print("Here are your scores for the term:") 
for score in scores:
    print(score)

For Practice... go to https://codingbat.com/python. There you can practice basic syntax and lists!


If you need anything, don't hesitate to reach out!

Contact us with any questions:

Mana Vale: nvale@exeter.edu

Rachael Kim: skim1@exeter.edu

Kaitlyn Flowers: kflowers@exeter.edu

Celine Tan: cltan@exeter.edu

Joey Dong: jdong1@exeter.edu

Molly Pate: mpate@exeter.edu

0 views

Recent Posts

See All

Web Programming Class 3

In class 3, we went over some more basics of HTML and CSS. Adding external links to your webpage <a href="google.com">LINK</a> Above code will produce a link to Google. *NOTE: codepen.io does not let

Phillips Exeter Academy Girls Who Code

Phillips Exeter Academy

20 Main Street

Exeter, NH 03833

Quick Links

© 2020 by Exeter Girls Who Code

This site was designed with the
.com
website builder. Create your website today.
Start Now