2.2.1 programming fundamentals Flashcards

1
Q

what are the three basic programming constructs

A
  • sequence (printing and variables)
  • selection (using if statements)
  • iteration (for and while loops)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what does MOD do (%)

A

give the remainder value
eg. 10MOD3 is 1
because 10/3 is 3 with remainder 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what does DIV do ()

A

divides and ignores remainders
eg. 10DIV3 is 3
because 10/3 is 3 with remainder 1 which is ignored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how to find length/how many characters in a string stored in a variable

A

print(VariableName.length)
- incudes spaces
or len(VariableName)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how to make string stored in variable uppercase

A

print(VariableName.upper)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how to make string stored in variable lowercase

A

print(VariableName.lower)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how to only print part of string stored in variable

A

eg. variable = computer science
print(variable.substring(0,8)) = computer
(0,8) as computer has 8 letters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how to convert a letter into ASCII value

A

print(ASC(letter))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to convert ASCII value into a letter

A

print(CHR(ascii number))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

if year = 2000 what does year += 20 do

A

year will now be stored as 2020

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is boolean value true and false stored as

A

1 = true 0 = false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how to only print one character of a string stored in a variable

A

print(VariableName[2]) would print the third letter of the string
- starts from 0 therefore third instead of second

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to print the last character of a string stored in a variable

A

print(VariableName[len(VariableName) - 1]
or print(VariableName[-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is slicing

A

returning part of the string stored in a variable (using substring)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to make a string stored in a variable backwards

A

print(VariableName ::-1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a nested if statement

A

if statement within an if statement

17
Q

how to slice a string

A

eg. name = “Riana”
print(name[0:3]) will print ria