Team One Lesson

3.1-3.2 Data Types, Variables, Lists, Strings, Data Abstraction, Managing Complexity

Hacks One 1.1 (Data Types and Variables)

  • This hack below has helped me develop further understanding of the different situations in which you would use integer, string, or boolean variables and how to use them.
    • integers are used for numbers
    • strings are used for words non-numerical values
    • boolean variables are used for describing variables as true or false
  • Below I have used the three different variable types. I can use this knowledge on the AP test to answer the questions about variable types and identifying them.
age = 15  #integer
favorite_color = "pink" #string
alive = True #boolean

print("This person is " + str(age) + " and their favorite color is " + favorite_color) 
#having the variables named like this make the variables usable and easily identifiable

if alive == True:
    print ("This person is alive")
else:
    print ("This person has passed away")
This person is 15 and their favorite color is pink
This person is alive

Hacks 2 3.1.2 (Variables)

  • This hack below has futher developed my understanding in variables and how to assign a value to one. I also learned how colledgeboard would represent assignment with variables and how the print function prints the latest value of the variable. I can use this to answer questions on my AP test related to assigning variables in complex algorithims.
  1. An assignment operator, like the "=" in python, assigns a value to a variable. Assignment operators can assign strings, integers, and booleans to variables. This allows for a user to use the variables in various functions.

  2. In Colledgeboard pseudocode, the symbol "<--" is the assignment operator (assigns values to variables).

  3. The print command will print the latest value of a variable. Due to the value of x being changed to 22, the command will display 22, not 15.

Hacks 3 3.2.1 (List and Strings using Variables)

  • This hack below has helped me to further develop my understanding of what a list is. Lists have a limited number of values that are in a specific order. I also did not know what an element was but now I know that it is a value within a list. I also learned that indexing is an easy way to access elements in a list. This is very helpful for collegeboard because the AP test has many questions about indexing.
  • I went above and beyond in this hack to continue to develop my understanding. Instead of just making a simple list, I also created a dictionary of lists, and learned how to index elements within the lists in the dictionary.
  1. A list is a finite series of ordered values.
  2. An element is a value within a list.
  3. An easy way to reference the elements in a list or string is by indexing. You can use the print function to print a specific element in a list.
  4. An example of a string is "apple".
favfoods = ["mac and cheese", "pizza", "pasta", "Goldfish"] #normal list
print(favfoods[3]) #this prints the fourth element (index 3) because in python the index starts at 0
print(favfoods[-1]) #This prints the fourth element as well


#below is a dictionary of lists to show my understanding

awesomefoods = {
    "Pastas" : ["bowtie", "penne", "macaroni"],
    "Deserts" : ["ice cream", "cake", "cupcakes", "milkshake", "brownies", "pie"],
    "Drinks" : ["Fanta", "Shirley Temple", "Sprite", "Coke", "Pepsi"]
}

#indexing the elements within the lists within the dictionary
print(awesomefoods["Pastas"]) #This will print all the pastas in the pasta list
print(awesomefoods["Deserts"][3]) #This will print out the fourth element in the deserts list
print(awesomefoods["Drinks"][-2]) #This will print the fourth element in the drinks list
Goldfish
Goldfish
['bowtie', 'penne', 'macaroni']
milkshake
Coke

Hacks 4 3.2.2 (Data Abstraction with Lists)

  • This hack has helped me to understand how to add input into a list, define the list, and then use the list to loop through the values and add to them.
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)]

# 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]

Hacks 5 3.2.3 (Managing Complexity)

  • This quiz helped me check my understanding for the AP exam on lists and dictionaries. Lists and dictionaries are essential topics on the AP exam.
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, avac54765 running /bin/python3
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!
avac54765 you scored 3/4

Below is my simplified list of the "long way" list. This has shown me how lists make programming much more efficient and make it easier for other programmers to understand.

foods = ["pizza", "hot dog", "sushi", "strawberry", "sandwich"]
print(foods)
['pizza', 'hot dog', 'sushi', 'strawberry', 'sandwich']

Question Answered: Using lists are better for a program, rather than writing out each line of code, because lists manage complexity within a program. It is much easier and saves a lot of time to organize values in a list. Lists also make it easier for other programers to understand a program instead of tracking numerous variables. Writing out each line of code takes a lot of time as well, and can get very tiring as you add more values to a program.

Below is my list that I have created the slow and efficient way. After this experience I definetely would use the efficient way of creating a list.

friend1 = "Alexa"
friend2 = "Lydia"
friend3 = "Jessica"
friend4 = "Nicole"
print(friend1, friend2, friend3, friend4)

# below is a list of my friends with managed complexity

friends = ["Alexa", "Lydia", "Jessica", "Nicole"]
print(friends)
Alexa Lydia Jessica Nicole
['Alexa', 'Lydia', 'Jessica', 'Nicole']

Team Two Lesson

Algorithims, sequence, selection, iteration, mathmatical expressions, MOD, string concatination

Hack 1 3.3.1

  • This hack has helped me to check my understanding on the difference between selection, iteration, and sequencing. I remember this topic being challenging to me when we first were given the table for the collegeboard requirements. I can now use this knowlege to make sure I have these requirements in my projects and can now identify these different algorithims on the AP exam.
  • sequencing: steps one, two, five (specific steps in order)
  • selection: step three (if statement= two choices)
  • iteration: step 4 (loop)

Hack 2

  • This hack has helped me understand how mathematical expressions are written in python and how MOD works. I can use this knowledge on the AP exam when analyzing different mathematical algorithims in which I have to come up with an output.

My work for evaluating the code above:

num 1 = 5 num 2 = 15 num 3 = 3 1 4 = 12 result = (2 + 15) % 12 3/5 = 5 3/5 = 3 ^ result = 3

Crossword puzzle answers:

  1. iteration
  2. selection
  3. sequence

Hack 3 3.4

  • notes for collegeboard pseudocode:
    • len returns the number of characters in the string
    • concat returns a single string of str 1 and str 2
    • substring (st1, str2, length) returns a substring of the characters from start to length
  • This hack has helped me to check my understanding with string concatination. Not going to lie, the substring was confusing to me, but this quiz had a question that allowed me to see another example and understand how it worked.

Extras to Further Develop my Understanding

Khan Academy is a great resource for learning about programming and the topics we are learning in class. I decided to take two quizzes on Khan Academy about this week's topics:

  1. A quiz about variables:

    • This quiz tested my knowledge on variables and how they are assigned
    • This quiz reviewed how sequencing works with variables and their assignments.
  2. A quiz about mathematical expressions:

    • This quiz tested my knowledge on math expressions. This quiz tested more the logical part of these expressions and the different ways to write code to match the logic. This helped me realize that there is more than one way to write code for different expressions.
    • This quiz included MOD, one of the topics that was newer to me this week. I got to see MOD in a more logical and real life situation (example: chocolates being divided amongst people and counting the extras).