Chap 8 - programing - print, if/elif/else, loops, len, string manipulation Flashcards

1
Q

name 6 data types

A

-integer
-string
-boolean
-float
-character (char)
-date

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

how do you use the print function

A

print(“ “)

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

2 ways you can print messages on print function

A

-comma
-concatenation (adding)

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

meaning of concatenation

A

join together

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

how do you use comma when printing

A

use comma between words

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

how do you use concatenation when printing

A

use ( + ) to add the strings

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

what is the difference between using comma and concatenation

A

space in comma, no space in concatenation

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

can you add strings

A

yes

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

can you add strings and integers

A

no

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

what data types are \t and \n

A

strings

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

what must you put when using \t and \n

A

quotations

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

what does \t do

A

a tab of space

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

what does \n do

A

a new line

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

what does = do

A

assignment of variable

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

what does != mean

A

not equal

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

3 rules for variables

A

-has to start with a char
-case sensitive
-no special char and spaces - willc hange program (except underscore)

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

operation for addition

A

+

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

operation for subtraction

A

-

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

operation for multiply

A

*

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

operation for division

A

/

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

operation for power

A

**

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

operation for squared

A

**(1/2)

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

operation for division (reminder)

A

%

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

operation for division (float)

A

/

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

operation for division (integer)

A

//

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

operation for not equal to

A

!=

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

which takes place first: maths operations or assignment of variable

A

maths operations

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

what is a list

A

-stores a list of items
-temporary

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

what is a tuple

A

-stores fixed items
-permament

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

how do you use list

A

fruits = [“apples”,”orange”]

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

how do you use tuple

A

fruits = (“apples”,”orange”)

32
Q

note: explain each thing when explaining assignment

A

eg. c = a=b
- c: variable
- +: addition of a and b
- =: assignment of variable

33
Q

what does = do

A

assignment of variables

34
Q

what does == do

A

comparison
eg. if (username == “butt”)

35
Q

how do you find input for string

A

input(“ “)

36
Q

how do you find input for integer

A

int(input(“ “))

37
Q

how do you find input for float

A

float(input(“ “))

38
Q

can integer be stored in float, why

A

-yes
-integer requires less memory than float

39
Q

can float be stored in integer, why

A

-no
-float requires more memory than integer

40
Q

what is the drawback of integer and float stored as string

A

they’ll be used as a string - lose their properties kinda

41
Q

can integer and float be stored in string

A

yes

42
Q

how do you use if conditional statement

A

if ( ):
, start here

43
Q

how do you use elif conditional statement

A

elif ( ):
, start here

44
Q

how do you use else conditional statement

A

else:
, start here

45
Q

how do you use nested ifs’

A

if ( ):
if ( ):

46
Q

how do you use and conditions in conditional statements

A

eg. if ( age> 10 and age< 20):

47
Q

how do you use conditional statement to get something in between value

A

eg. if (0 < username <10):

48
Q

how do you use or conditions in conditional statements

A

eg. if ( age> 10 or age< 20):

49
Q

nota: % - remainder, // - integer, / - float (for division)

A
50
Q

note: all chars are strings, not all strings are chars

A
51
Q

note: can add and & or to conditions

A
52
Q

Iteration

A

looping

53
Q

why are looped required

A

use same algorithm for diff. inputs

54
Q

types of loops

A

-for
-while

54
Q

basic structure of loops

A

-initializer- variable which controls if loop is done or not
-action
-stopping condition
-updating counter/ no. loops

55
Q

how to write for loop

A

-for i in range (____):
-for i in (variable/ list/ str)
(i changed to elements in variable/ list/ str)
(auto counter update)

56
Q

how to update counter

A

i = i+1
i +=1

57
Q

how to write while loop

A

i = 0
while (____):
i +=1
(manuel counter update)

58
Q

how does range function work

A

eg, (0, 5) - no.s - 0, 1, 2, 3, 4, - no 5
(0, 20, 2) - no.s 0-19, with 2 step btw (eg, 0, 2, 4…)
(variable/ list/ str) = no.s in that variable, list

59
Q

diff btw for & while loops

A

-for is repeated a known no. times
-while is repeated for unknown no. times

60
Q

what is i called in loops

A

iterating variable

60
Q

types of loop control statements

A

-break
-continue
-pass

61
Q

how to use break loop control

A

-write break within loop
-stop loop
-if used in nested loop, it stop the inner most loop

62
Q

how to use pass loop control

A

-write pass within loop
-null statement- nothing happens when statement is executed

62
Q

how to use continue loop control

A

-write continue within loop
-skips current iteration and jumps to next loop

63
Q

how to write loop/if/elif with a list as its range

A

n= [“A”, “B”]
-for i in n:
-while i in n:
-if variable[i] in n:
-elif variable[i] in n:
note: i changes to elements in list, list can be any data type

64
Q

index values in list

A

-all char has an index value
-first element = 0 - positive
-last element = -1 - negative

64
Q

index values of char in list

A

-first char is 0
-last char is -1

65
Q

note: space is considered a char so has an index value

A
66
Q
A
66
Q

how to use len function

A

-finds no. elements in a list - list can be of any data types
n = [1,2,3]
length = len(n)
print(length)

66
Q

how to extract a certain char from a list

A

num = [1,2,3,4]
- print(num[ 0 ]) = 1
-print(num[ 0: ]) = 1, 2, 3, 4
-print(num[ 0:2]) = 1,2 (index after : not included)
-print(num[:2]) = 1,2 (index after : not included)
-print(num[-1]) = 4
-print(num[i:i+ n ]) = value with i index & n no.s after it

67
Q

diff btw in range of loops -

A

-for i in range (10, lengthData+10):
= i starts from 10th index - if range i beyond elements in list = index error
-for i in range (0, lengthData):
= i starts from 0th index

68
Q
A
69
Q
A