Variable and Abstraction Notes
Welcome to my Variable and Abstraction Notes
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
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
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