Sections 3.1 and 3.2
Variables:
- make them specific but short and easy to read/write repeatedly
- differentiate words w capital letters
- dont make them vague, dont use single letters as variables
- NO SPACES
Types of Data:
- integer: numbers
- string: words/text -boolean: determines if something is true or false
Assignments:
- allows the program to change the value of a variable
num1 = 15
num2 = 25
num3 = 42
num2 = num3
num3 = num1
num1 = num2
print(num1)
print(num2)
print(num3)
Data Abstraction
- method used to represent data in a useful way
- only displays data relevant to the situation
- managing complexity
Using lists as data abstractions
- store multiple elements together
- allows multiple related values to be treated as one things
List operations:
- assigning values to a list
- assigning an empty list to a variable (to be used later on)
- Assigning a copy of one list to another list
Managing complexity
- can be read easier
- easier to find issues in code or can be updated early on
- lists help because they limit the amount of variables needed and can be easily changed
colors = ["green", "red", "pink", "purple", "blue", "brown"]
for x in colors:
print(x)
print("Hello. Which dog breed would you like to know about?")
print("options: golden retriever, labrador, husky, border collie, german shepard")
#golden retriever
GoldR_DB = {
"Breed": "Golden Retriever",
"Life span": "10-12 years",
"Temperament": ["Intelligent, Reliable, Kind, Trustworthy"],
"Weight": "55-75 lbs",
"Height": "20-24 in",
}
#labrador
Lab_DB = {
"Breed": "Labrador",
"Life span": "10-12 years",
"Temperament": ["Outgoing, Agile, Intelligent, Trustworthy"],
"Weight": "55-71 lbs",
"Height": "22-24 in",
}
#husky
Husky_DB = {
"Breed": "Husky",
"Life span": "10-16 years",
"Temperament": ["Loyal, Playful, Intelligent, Friendly"],
"Weight": "44-66 lbs",
"Height": "22-24 in",
}
#border collie
BordColl_DB = {
"Breed" : "Border Collie",
"Life span" : "10-17 years",
"Temperament" : ["Energetic, Keen, Alert, Athletic"],
"Weight": "27-45 lbs",
"Height": "19-22 in",
}
#german shepard
GermShep_DB = {
"Breed" : "German Shepard",
"Life Span" : "9-13 years",
"Temperament" : ["Stubborn, Confident, Courageous, Protective"],
"Weight" : "49-71 lbs",
"Height" : "22-26 in",
}
def users_pick(prompt):
msg = input()
return msg
#prints according to input
rsp = users_pick("enter breed here:")
if rsp == "golden retriever":
print(" ")
print("Golden Retriever Info:")
print(" ")
for key, value in GoldR_DB.items():
print(key, ":", value)
elif rsp == "labrador":
print(" ")
print("Labrador Info:")
print(" ")
for key, value in GoldR_DB.items():
print(key, ":", value)
elif rsp == "husky":
print(" ")
print("Husky Info:")
print(" ")
for key, value in Husky_DB.items():
print(key, ":", value)
elif rsp == "border collie":
print(" ")
print("Border Collie Info:")
print(" ")
for key, value in BordColl_DB.items():
print(key, ":", value)
elif rsp == "german shepard":
print(" ")
print("German Shepard Info:")
print(" ")
for key, value in GermShep_DB.items():
print(key, ":", value)
else:
print("error; please type in one of the given options")