Notes from slide

Essential Knowledge (College Board's Must Knows):

  • A variable is an abstraction inside a program that holds a value, where each variable has associated data storage that represents a single value at a time (However, if the value is a collection type such as a list, then the value can contain multiple values).
  • Variables typically have meaningful names that helps with the overall organization of the code and understanding of what is being represented by the variables
  • Some programming languages provide a variety of methods to represent data, which are referenced using variables 9Booleans, numbers, lists, and strings)
  • One form of a value is better suited for representation than antoher.

What is a Variable?

A variable is an abstraction made inside a program that holds a value. These variables are used in code to refer to more comples values that the variable contains and makes the program code more organized and smoother to run.

Variables can be seen as "containers" and each container has a name that holds what it is supposed to hold. In the following code, we can see that a variable has the value of "Alex." How can we make the variable appear more organized in the code?

Questions (College Board's Essential Knowledge):

  1. What exactly IS a variable?
  • A variable is a abstraction in a program that holds a value. These are used to make programs run faster.
  1. What is the best data type to represent someone's dog's name?
  • A string
  1. Why is it important to give variables specific names before containing values?
  • So you can use them later in the program.
  1. What is the best way to represent someone's phone number?
  • A string

Hacks:

Answer these:

  1. In your own words, briefly explain by writing down what an assignment operator is
  • A assignment operator defines a variable.
  1. In Collegeboard pseudocode, what symbol is used to assign values to variables?
  • <
  1. A variable, x, is initially given a value of 15. Later on, the value for x is changed to 22. If you print x, would the command display 15 or 22?
  • It would display 22

Questions

  • What is a list? Multiple variables defined in a simple way
  • What is an element Items inside the list
  • What is an easy way to reference the elements in a list or string? print
  • What is an example of a string?
  • A list of numbers

Hacks

  • Create a list with indices
  • Index a part of the list that you created.
  • Try to index from the end
colors = ["Yellow", "Green", "Blue"]
print(colors[2])
Blue
num1=input("Input a number.")
num2=input("Input a number.")
num3=input("Input a number.")
add=input("Input a number.")

# Add code in the space below
numlist = [int(num1), int(num2), int(num3)]
print("User submitted numbers", numlist)
print("Plus " + add)


# 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)
User submitted numbers [1, 2, 3]
Plus 3
[4, 5, 6]
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, lukavandenboomen running /Users/lukavandenboomen/opt/anaconda3/bin/python
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 incorrect!
Question: Lists are a form of data ______
Abstraction is incorrect!
Question: Which brackets are used to assign values to a variable to make a list?
[] is correct!
lukavandenboomen you scored 1/4