other computing Flashcards
Open
file = open(“quick.txt”, “_”)
Read
file = open(“quick.txt”, “r”)
quicktext = file.read()
Close
Write (overwrite)
file = open(“quick.txt”, “w”)
Append (add to)
file = open(“quick.txt”, “r”)
Turtle commands
All on the PLS.
Import turtle with import turtle
List
a type of data structure that can be used to manipulate the elements they contain.
Array
a kind of data structure that can hold a number of items grouped together. it contains a number of items grouped together, and named using a single identifier, however can only hold the same data type.
Procedures
Carries out an action but doesn’t return a value
Functions
Carries out an action and returns a value
Data structure
store data in an organised and accessible way. They can be static or dynamic.
Dynamic data structure
more flexible. The memory capacity is not fixed.
Static data structure
reserves memory locations for a set amount of data. Their size cannot change.
String format
print(”Alice has {} cupcakes.”.format(5))
Record
Stores a collection of attributes/fields for a single entity.
Static data structure
Database
Stores many records for a single entity
How to do a record in python
Use a dictionary to represent a record
player1 = {“username” : “rockstar”,
“password” : “6goatsEating”,
“score” : 5328}
player2 = {“username” : “dynomouse”,
“password” : “Skibidi”,
“score” : 8594}
player3 = {“username” : “australiahead”,
“password” : “FanumTax”,
“score” : 9999}
players = [player1, player2, player3]
print (players)
Linear search
Goes through every item in a list to see if it’s correct
- Take a list of data and an item that is being searched for (the search item)
- Repeat steps 3-5 starting from the first item in the list, until you find the search item or until the end of the list is reached:
- Compare the item at the current position to the search item
- If the item at the current position is equal to the search item, then stop searching.
- Otherwise, go to the next item in the list.
Binary search
- Take an ordered list of data and an item that is being searched for
- Maintain a range of items where the search item might be found. Initially, set the range to be the entire list.
- Repeat steps 4-8 until you find the item you are searching for or there are no more items to check (the range is empty):
- Find the item in the middle of the range (the midpoint item).
- Compare the midpoint item to the item you are searching for.
- If the midpoint item is equal to the search item, then stop searching.
- Otherwise, if the midpoint item is less than than the search item, change the range to focus on the items after the midpoint.
- Otherwise, if the midpoint item is greater than than the search item, change the range to focus on the items before the midpoint.
Bubble sort
Bubble sort works by repeatedly going through a list, comparing adjacent items and swapping the items if in the wrong order.
Merge sort
- Take a list of data to be sorted.
- Repeatedly split the list in half (life) until each item is in a list of it own.
- Repeat steps 4-5 until all lists have been merged.
- Take two lists of data to be merged.
- Create a new empty list for the merged items.
- Repeat steps 7-9 until one of the lists of items is empty.
- Compare the first items of the two lists.
- Place the item that is lower into the merged list in the next available position.
- Then place each item from the remaining list into the merged list in order.