2.2.1 programming fundamentals Flashcards
what are the three basic programming constructs
- sequence (printing and variables)
- selection (using if statements)
- iteration (for and while loops)
what does MOD do (%)
give the remainder value
eg. 10MOD3 is 1
because 10/3 is 3 with remainder 1
what does DIV do ()
divides and ignores remainders
eg. 10DIV3 is 3
because 10/3 is 3 with remainder 1 which is ignored
how to find length/how many characters in a string stored in a variable
print(VariableName.length)
- incudes spaces
or len(VariableName)
how to make string stored in variable uppercase
print(VariableName.upper)
how to make string stored in variable lowercase
print(VariableName.lower)
how to only print part of string stored in variable
eg. variable = computer science
print(variable.substring(0,8)) = computer
(0,8) as computer has 8 letters
how to convert a letter into ASCII value
print(ASC(letter))
how to convert ASCII value into a letter
print(CHR(ascii number))
if year = 2000 what does year += 20 do
year will now be stored as 2020
what is boolean value true and false stored as
1 = true 0 = false
how to only print one character of a string stored in a variable
print(VariableName[2]) would print the third letter of the string
- starts from 0 therefore third instead of second
how to print the last character of a string stored in a variable
print(VariableName[len(VariableName) - 1]
or print(VariableName[-1]
what is slicing
returning part of the string stored in a variable (using substring)
How to make a string stored in a variable backwards
print(VariableName ::-1)