Notes:

  • variable
    • holds a value
  • data types
    • integer
    • string
    • boolean
  • assignment operator
    • college board uses: <-
  • list index
    • python lets u index from front of list and back of list
  • long and short way to print lists
    • short way better
    • able to write code in shorter length and with less clutter
  • assignming values to one variable
    • uses []

Hacks:

What is a variable? (3.1.1)

Code with variables:

name = input("What is your name?")
# use of integers
age = 15

print(f"Hey my name is {name} and I am {age} years old.")
Hey my name is claire and I am 15 years old.

Variables (3.1.2)

Questions:

  1. An assignment operator assigns a new value to a variable.
  2. <- is the symbol collegeboard psuedocode uses
  3. 22

Lists (3.2.1)

Questions:

  1. A list is something that is used to store multiple variables in one variable. It is in brackets and separated with commas.
  2. Individual strings that are inside of the list.
  3. index the list or string (ex. list[1])
  4. an example of a string is "hey guys"
favfoods = ["acai", "pasta", "thin mints", "coffee"]

print(favfoods[0])
print(favfoods[-2])
acai
thin mints

Data Abstraction with Lists (3.2.2)

num1 = input("Input a number. ")
num2 = input("Input a number. ")
num3 = input("Input a number. ")
add = input("How much would you like to add? ")

# Add code in the space below
num1 = int(num1)
num2 = int(num2)
num3 = int(num3)

numlist = [num1, num2, num3]

# The following is the code that adds the inputted addend to the other numbers. It is hidden from the user.

for i in numlist:
    numlist[i-1] += int(add)

print(numlist)
[5, 6, 7]

Managing Complexity with lists (3.2.3)

import getpass, sys

def question_with_response(prompt):
    print("Question: " + prompt)
    msg = input()
    return msg

questions = 4
correct = 0

print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_with_response("Are you ready to take a test?")

rsp = question_with_response("The purpose of lists and dictionaries are to manage the ____ of a program")
if rsp == "complexity":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("Lists are a form of data ______")
if rsp == "abstraction":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("Which brackets are used to assign values to a variable to make a list?")
if rsp == "[]":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!") 

print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
Hello, clairezhao running /opt/homebrew/opt/python@3.10/bin/python3.10
You will be asked 4 questions.
Question: Are you ready to take a test?
Question: The purpose of lists and dictionaries are to manage the ____ of a program
complexity is correct!
Question: Lists are a form of data ______
abstraction is correct!
Question: Which brackets are used to assign values to a variable to make a list?
[] is correct!
clairezhao you scored 3/4
food1 = "pizza"
food2 = "hot dog"
food3 = "sushi"
food4 = "strawberry"
food5 = "sandwich"
print(food1, food2, food3, food4, food5)

foods = ["pizza", "hot dog", "sushi", "strawberry", "sandwich")
print(foods]
pizza hot dog sushi strawberry sandwich
('pizza', 'hot dog', 'sushi', 'strawberry', 'sandwich')
  • Lists are better for a program rather than writing lines of codes because it makes things written in less lines of code so that it is easier to read and less of a mess when looking at the code. Code that some would write in 10 lines can be written in 10
temp1 = 66
temp2 = 72
temp3 = 63
temp4 = 79
temp5 = 60
temp6 = 82
print(temp1, temp2, temp3, temp4, temp5, temp6)

# short way
temperature = [66, 72, 63, 79, 60, 82]
print(temperature)
66 72 63 79 60 82
[66, 72, 63, 79, 60, 82]