Shared Flashcard Set

Details

Week 3
programming principles
13
Computer Science
Post-Graduate
11/08/2017

Additional Computer Science Flashcards

 


 

Cards

Term
Define data structure and how it differs from data type
Definition
Data types are categories of data. Data structures allow multiple pieces of data to be stored in an organised structure. Like data types, data structure define what you can do with it.
Term
Array
Definition
Common data structure which is an ordered collection of values. ie items have a set position within the array. This allows you to sort, count, determine min/max, search for a value. You can refer to an item in an array by its index []
Term
Difference between lists and tuples

Similarities
Definition
lists created with [],mutable (can change / add)
tuples with (), immutable (can't add / change)

Both ordered, able to contain different data types and reference by index
Term
code to add 5 to nums = [1,2,3,4]

refer to middle three letters in paradox
Definition
nums.append(5)

values [2:5]
Term
"in" comparison operator
Definition
allows you to search for an item in a data structure (list, tuple or even string)
eg num = [2,4,6,8]
if 4 in num:
print ('4 is in num')
else
print ('4 is not in num')

you can also use not in as an operator
Term
For Loop
Definition
Control structures (like selection statements) For: counter controlled loop. used when the number of iterations is known in advance for in : variable is name for current item and sequence is any iterable thing (list, tuple, range etc) for num in range (1,11): print (num) #will print 1 - 10 for num in range (6): print (num) #will print 1 - 5 draw flow chart
Term
While loop
Definition
Condition controlled loop. Repeats the loop body while the condition is true. The condition is checked before each repetition and if flase, body is not run.

Draw flowchart
Term
Difference in syntax between while loops in python and most other languages
Definition
python: while :


Other: while ()
{

}
Term
Difference in while and do-while loops
Definition
Draw flow chart Do-while loop can be replicated using a while loop while True: if : break
Term
Break statement
Definition
ends the loop right away and moves on to the next statement after the loop. Used within a selection statement in the body of a loop. Can be used in any type of loop and almost all languages. Often be used to end an otherwise infinite loop.
Term
Continue statement
Definition
Skips the rest of the loop body and then continues with the next iteration.
Term
Two main styles of 'for' loops
Definition
For loops come in two main styles:
A counter-controlled loop which works its way through a sequence (Fortran, ALGOL, Ada, BASIC, Ruby, Python…)
The original style of for loops

A generic condition-controlled loop which is usually used in a counter-controlled fashion (C, C++, Java, PHP, JavaScript…)
Very common, and sometimes referred to as a “C-style for loop”
Term
Range function
Definition
range ()
Allows you to loop through a set of numbers within a range

for num in range (1,11):
print (num) #prints 1 - 10

for num in range (1,22,3):
print (num) #prints every third num between 1 and 21
Supporting users have an ad free experience!