Shared Flashcard Set

Details

Week 4
programming principles
15
Computer Science
Post-Graduate
11/08/2017

Additional Computer Science Flashcards

 


 

Cards

Term
Functions
Definition
Group of statements that exist within a program for the purpose of performing a specific task.

Give you a way of performing a task without needing to know how it is done.

Helps modularise the program
Term
Purpose of four built in python functions
Definition
print() - display the value (output)

input() - prompt for an input

len() - measure length of data structure

int() - convert to integer

float() - convert to float

str() - convert to string
Term
Benefit of writing your own functions
Definition
- simpler code (readability)
- code reuse
-better testing
- faster development
- easier teamwork (can break up the problem)
Term
5.Write Python code for a function named "increment" which takes a parameter, adds 1 to it, and returns the result.
Definition
def increment(prompt):
while True:
val = input(prompt)
try:
intVal = int(val) +1
print(intVal)

except ValueError:
print ('Invalid input: enter an integer.')
continue

increment('Enter a value:')
Term
Write/Draw examples of pseudocode and a flowchart that involve a function call.
Definition
call functionName function

[image]
Term
Local variable
Definition
variable created inside a function and it's scope is limited to that function
Term
global variable
Definition
Variable created outside a function (main code) which can be accessed from any function
- shouldn't use inside functions as you prob can't reuse, errors are harder to track down and programs harder to understand. Makes the functions dependent with the code
Term
Parameters in functions
Definition
Define the data that can be passed into the function.
Much better then using global variables in a function. Can reuse with different parameters which then become the local variables
Term
Return statements in functions
Definition
Allow us to return data from function. Keeps them independent. Could be a data structure.
return
Term
built-in functions
Definition
Already exist within the language and used to perform common tasks. Don't need to be imported.
Term
standard library modules
Definition
Specialised packages of functionality that are always included w the language but need to be imported eg. random, math
Term
external modules
Definition
specialised packages of functionality that are not included w the language and often developed by 3rd party. Need to be downloaded and imported
Term
process of external modules
Definition
1. User needs functionality that is not available
2. User writes code to achieve it
3. User generalises and polishes
4. user releases to public
Term
considerations using external modules
Definition
- might not be compatible with version you are using
- might not be as well coded, tested or maintained as standard library modules
-could have significant security vulnerabilities
Term
Write Python code that imports the random module and uses the "randint()" function from it.
Definition
import random

val = random.randint (1,6)
print (val) #print random integer between 1 and 6
Supporting users have an ad free experience!