Section 2 Flashcards
What is a variable?
Is used in programming to store data
What is a constant?
Is a variable that cannot be changed during the execution of the program
Data Type: String
zero or more characters in a quote mark
Data Type: Real/Float
Decimals
Data Type: Boolean
Only accepting true or false
What is camelCase and its advantages?
To separate words by making first letter of second word capitalized
Advantages are: Easier to remember Consistent
What is snake_case?
Where all words are in lowercase and are separated by an underscore
E.G. max-number-of-players
Could be used to name functions
What is PascalCase?
Each word separated by capitalizing the first letter of each word?
String conversion: int(input(
Allows integer to be an input or part of string
String conversion: float(input(
Allows decimal to be an input or part of string
String conversion: str
Just means string
To add
+
To subtract
-
To multiply
*
To divide
/
MOD(modulus)
%(finds the remainder)
DIV(quotient)
// finds the quotient (the number before the decimal point)
Exponentiation
^/** used to find the power
not equal to
!=
Equal to
==
less than
<
less than equal to
<=
greater than
>
greater than equal to
> =
Selection
if and else statements
condition controlled iteration
While, endwhile
Iteration
A for end for loop is a definite count controlled loop
Data Structure: Array
A structure used to hold multiple Items of the same type
e.g. day=[“MON”,”TUES”,”WED”]
Two-Dimensional Arrays
Sales[58,56,43,67][etc,etc,etc][etc,etc,etc]
String manipulation: What does concatenating mean?
Joining together
String manipulation: Index
Starts at 0
String Manipulation: If student name = “Jumal”
in terms of index what position is letter J?
studentName[0] = “J”
Substrings: how to isolate part of a string?
e.g. productCode=”GAR201834”
Isolate into GAR2018
productType = productCode[0:3]
year=productCode[3:7]
print(“productType=”,productType)
print(“Year=”,year)
This will print:
Product type=GAR
Year=2018
How to find length of string?
len(mystring)=length of my strength
It includes all characters and even spaces
Find first n characters of a string?
nChars= myString[0:n]
Subroutines
Named block of code, separated from the main program
two types: functions and procedures
functions returns a value to a variable with a specified call
Advantages of subroutines
-debugging and maintaining is easier as they are short code
-Subroutines can be easily tested to be correct separately
-particular subroutine can be called several times saved in a library and used in other programs
How to generate a random number?
First off import random for any random operation
Then random.randint(a,b)
a,b = between two numbers
Robust and secure programming
Data validation techniques used to check validity of data the user has entered
Testing
ensure only input or execution of program works properly
Techniques for Robust and secure programming
-Length Check: string entered must be greater or equal to minimum length
-Presence Check: string should not be empty
-Range Check: data must lie within given range
-Authentication: test if person is who they say to be e.g. fingerprint, facial recognition, password
Techniques for Testing
-Syntax error: prevent program running because of spelling or grammar mistake
-Logic error: harder to spot.May run but may crash or give an incorrect or unexpected output
Selecting and using suitable test data:
Normal Data
using examples of typical data that the program is designed to handle
Selecting and using suitable test data:
Boundary data
which includes both ends of the allowed range as well as invalid data
Selecting and using suitable test data:
Erroneous data
data of the wrong type e.g. non-numeric characters numeric field