2.2.1 Programming fundamentals Flashcards
sequence =
= one line of code after the other
selection =
= IF, ELSE, ELIF - a way to control the flow of your program
iteration = (2 types)
= loops
count-loop stops when it has iterated a set number of times
condition loops - the loops stops when it has met a condition/decision
sequence example =
n1 = int (input(‘enter your 1st number ‘))
n2 = int (input(‘enter your 2nd number ‘))
answer = n1 * n2
print (‘The answer is’,answer)
selection example =
age = float(input(‘How old are you)
If age >= 18:
Print (‘adult’)
Else
Print(‘child’)
iteration - count
top = int(input(‘enter limit’))
for i in range (2, top+1,2):
print (i)
iteration - condition examples
name = ‘Mr carson’
while name != ‘Maeve’:
print (name,’is not a student)
name = input(“Enter a Students name”)
print (‘Maeve is definitely a student’)
+ =
= addition
— =
= subtraction
- =
= multiplication
/ =
= division
% =
= modulus (MOD)
eg. 10 % 4 = 2
// =
= quotient (DIV)
eg. 18 // 5 = 3
** =
or
^ =
= exponent
eg. 2 ** 4 = 16
AND =
= 2 or more conditions are True