Variable Notes

Variable is abstraction inside a program that can hold a value It organizes data by labeling it with a descriptive name Contains name, value, and type

Keep the variable short and general. Make sure it is understable. Don't use spaces in naming the variable

Types of data

  • Integer - A number
  • Text/string - A word
  • Boolean - true/false

Assignments Notes

Operators that allows a program to change the value represented by a variable by assigning values to variables

The value stored in a variable will be the most revent value assigned

Data Abstraction

Data abstractionis method used in coding to represent data in a useful form by taking away aspects of data that arent being used in the situation Variables and lists are primary tools in data abstraction

A list is ordered sequence of elements An element is an individual calue in a list that has a specific index

3 types of list operations

  • Assigning calues to a list at certain indices
  • Creating an empty list and assigning it to a variable
  • Assigning the value of one list to another list

Managing Comlexity

Managing complexity improves the readability of the code

Managing complexity also reduces the need for new variables as more data is collected

QandA = {
    "How many NBA championships has Bill Russell won?": "11", 
    "What was the last year that the Sacramento Kings made the playoffs?": "2006", 
    "Which player holds the record for the most points in a single game?": "wilt chamberlain", 
    "Which NBA player holds the all-time record for the most total assists?": "john stockton", 
}

def qandarsp(question):
    print(question)
    rsp = input()
    return rsp

correct = 0 

print("Current number of questions: " + str(len(QandA)))

for key in QandA:
    rsp = qandarsp(key)
    rsp = rsp.lower()
    if rsp == QandA[key]:
        print(f"Correct! Your answer was {rsp}")
        correct += 1
    else:
        print(f"{rsp} is incorrect") 

percent = round(correct/len(QandA), 2)*100

print("You scored " + str(correct) +"/" + str(len(QandA)))
print(f"This is {percent}%") # print score and percentage
Current number of questions: 4
How many NBA championships has Bill Russell won?
10 is incorrect
What was the last year that the Sacramento Kings made the playoffs?
Correct! Your answer was 2006
Which player holds the record for the most points in a single game?
Correct! Your answer was wilt chamberlain
Which NBA player holds the all-time record for the most total assists?
Correct! Your answer was john stockton
You scored 3/4
This is 75.0%