Notes

Variable: abstraction made inside a program

# Variable has a value of "Alex"
x = "Alex"
print(x)
Alex

Choosing Variables

When choosing a variable, it is important to assign its name to the something that correlates with the function of the variable is supposed to do.

Data Types

  • integers (numbers)
  • strings (or text/letters)
  • Booleans

The best data type to represent someone's dog's name is a string. The best data type to represent someone's phone number is an integer.

name = "Timmy"
age = "25"

print(name + " is " + age)
Timmy is 25

Hacks 1

age = "18"
name = "Shruthi"

print(name + " is " + age)
Shruthi is 18

Hacks 2

The assignment operator is the transition character of a variable. A variable is an abstraction made inside a program that holds a value. College board uses assignment operator <- In python, the assignment operator is an equal sign. A variable, x, is initially given a value of 15. Later on, the value for x is changed to 22. If you print x, the command would display 22.

Hacks 3

A list is a sequence of elements with each element being a variable. An easy way to reference the elements is in a list. Example of a string: "hello world"

Notes - List Index

songList = ["american pie", "country roads", "annie's song", "ladies love country boys"]
print(songList[2])
print(songList[-1])
annie's song
ladies love country boys

Hacks 3 continued

foodList = ["caulifour", "pizza", "egg curry", "circle-shaped eggplant"]
print(foodList[0])
print(foodList[-1])
caulifour
circle-shaped eggplant
<html>
    <body>
        <div class="container">
            <div class="calendar">
                <div class="month">
                    <button id="prev" onclick="prev()">Prev</button>
                    <button id="next" onclick="next()">Next</button>

                    <p id="month">Month Here</p>
                </div>
            </div>
        </div>

        <script>

            let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
            let index = 0;

            function next() {
                if (index > 11) {
                    index = 0;
                }
                else {
                    index += 1;
                }
                document.getElementById("month").innerHTML = months[index]
            }

            function prev() {
                if (index < 0) {
                    index = 11;
                }
                else {
                    index -= 1;
                }
                document.getElementById("month").innerHTML = months[index]
            }

            document.getElementById("month").innerHTML = months[index]

        </script>
    </body>
</html>

Hacks 4

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

numlist = [int(num1), int(num2), int(num3)]
print("Original numbers:",numlist)
print("Adding:",add)

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

print(numlist)
Original numbers: [2, 3, 4]
Adding: 5
[7, 8, 9]

Hacks 5

Python Quiz

  1. The purpose of lists and dictionaires is to manage complexity of a program
  2. Lists are a form of data abstraction
  3. We use [] to assign a variable to make a list

Notes

Long and Slow Way

food1 = "cauliflour" 
food2 = "pizza" 
food3 = "egg curry"
food4 = "circle-shaped eggplant"
print(food1, food2, food3, food4)
cauliflour pizza egg curry circle-shaped eggplant

Assinging values to one variable

scores = [95, 84, 85, 99]
print(scores)
[95, 84, 85, 99]