Values and Variable Flashcards

0
Q

Define value

A

A number or letter

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

What are five type of values?

A
  • integer
  • floating-point number
  • string
  • list
  • bool
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Type(2)

A

Class ‘int’

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

Type(‘Hello,World!’)

A

Class’str’

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

Type (‘2’)

A

Class’str’

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

Is 42.0 a integer, floating-point number or a string?

A

Floating-point number

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

What are the five conditions of creating a variable?

A
  • cannot contain spaces
  • can contain letters or numbers or both
  • cannot begin with a number
  • underscore (____) character are allowed
  • cannot contain Python’s keywords
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are 27 Python keywords?

A

False, none, True, and, as, assert, break, class, continue, def, del, elif, else, except, finally, for, from , global, if, import, in, is, lambda, nonlocal, not, or, pass, raise , return, try, while, with, yield

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

Define reassignment

A

Reassigning a variable with a new value. Ex. A=4. After reassigning A, now A=6

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

In Python, is equality a symmetric relationship? Why?

A

No because a=7 but 7=a is wrong. Variable cannot begin with a number

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

Define update

A

New value of variable depends on the previous value

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

Define initialize

A

To begin or start

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

Fun fact: example of update
»> x=2
»> x=x+1

A

Wow

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

Define increment

A

Updating a variable by adding 1

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

Define decrement

A

Updating a variable by subtracting 1

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

Why do we use variables in computers?

A

To make a computer manipulate data, we must tell the computer to remember the data by using variable

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

Define variable (3 definitions)

A
  • Memory(RAM) location
  • to which we give a name
  • to which we assign a value of a particular data type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Define floating-point number

A

Number with sig figs or with decimals

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

What are the two conventional ways to name a variable?

A
  1. Camelcase ex.finalLetterGrade

2. Use underscore between words. Ex.final_letter_grade

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

Is Python case sensitive?

A

Yes

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

Define operator

A

Special symbols that represent computation like multiple or add

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

What are examples of operators?(add,subtract,multiple, divide, and exponent)

A
\+=add
-= subtract
*= multiple
/= float/normal divide
**= exponent
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Define assignment statement

A

Creates a new variable with a new value.

Ex. A= 7

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

Define state diagram

A

Create a new variable with a new value using arrows

Ex. A —> 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Define expression
A combination of values, variables and operators
25
Define statement
A unit of code that has an effect like creating a variable or displaying a value
26
What does a newline look like?
\n
27
What is an example of a strongly-typed high level language?
C or C++
28
What is an example of a weakly-type high level language?
Python
29
What does GPS stand for in programming?
Good programming style
30
Define weakly-type high level language
You can store any value in a variable
31
Define strongly-type high level language
Must state the type of value before assigning a variable with a value.
32
What is the advantage of strongly-type high-level language versus weakly-type?
Weakly-type high level language are error-prone
33
Does Python automatically follow order of operations?
Yes
34
What does this symbol # mean in programming and what is its purpose?
means comments and it is good for explaining what the program does
35
Define concatenate
To join two operands end-to-end
36
Define exception
An error that is detected while the program is running
37
Define semantics
Meanings of a program
38
Define semantic error
An error within the program that makes it do something other than what the programmer intended
39
What is the symbol for floor division and what does it do?
// is the symbol for floor division l and rounds the number into an integer.
40
What is the symbol for modulus and what does it do?
% is the symbol for modulus and it divides two numbers and shows the remainder. Ex. 105%60 = 45
41
Define hand trace
Predicting the results of our code without the use of computer
42
What are 6 categories of statement?
``` Assignment statement Input statement Output statement Operational statement Iterate statement Conditional statement ```
43
True or false? Prompt must be a string
True
44
What are three conversion functions?
Int() Float() Str()
45
Define operand
Number being used in a operation
46
What does the built-in function look like for assignment statement?
Variable=value
47
Define argument
Data we want the function to use and act upon
48
What does the built-in function look like for input statement?
Input (prompt)
49
What does the built-in function look like for output statement?
Print (argument)
50
What does the built-in function look like for operational statement?
(Operand)(operator)(operand)
51
Which is a literal value? | A= 7
7
52
What are three type of errors?
- Syntax error - Runtime error - Semantic error
53
What is a Syntax error
Occurs when our Python code does not follow the Syntax rule
54
What is the runtime error?
Occurs when the user enters an invalid test data
55
What are two things that the test case contains?
- Test data: specific values | - Expected result: must be computed beforehand
56
Define returned values
When a function returns a result and that result is called a return value.
57
Define string concatenation
Joins strings by adding or linking them end-to-end. Example: >>>"first"+"second" "Firstsecond"
58
What is the result of this function and what is it called? | >>>"hi" * 3
"hihihi" | String repetition
59
What does an index look like and what does it indicate?
[] expression in brackets. It indicates which character in the sequence you want
60
Define string
It is a sequence of character
61
What will happen as a result of this function and what is it called? >>>fruit=banana >>>letter=fruit[1]
>>>letter=fruit[1] "a" B in banana is considered the 0th letter while A is considered the 1st Function called an index
62
What will happen as a result of this function and what is it called? >>>fruit=banana >>>letter=fruit[0]
>>>letter=fruit[0] "b" Function called an index
63
True or false? Index can be any number
False. Index must be an integer.
64
Define lens
Built-in function that returns the number of characters in a string Ex. >>>fruit="apple" >>>len(fruit) 5
65
What is the result of the following and what is the function called? >>>word= hi >>>len(word)
>>>word= hi >>>len(word) 2 Len function
66
Define slice
A segment of a string Example: >>> a="apple" >>>a[0:2] "Ap"
67
What will happen to the following and what is it called? >>> a="apple" >>>a[:2]
"Ap" | String slicing
68
What will happen to the following and what is it called? >>> a="apple" >>>a[2:]
"ple" | String slicing
69
Define empty string
When first string index is greater or equal to the second index
70
What will happen to the following and what is it called? Ex. >>> a=apple >>>a[3:3]
" " | Empty string
71
What will happen to the following and what is it called? Ex. >>> a=apple >>>a[6:3]
" " | Empty string
72
Define invocation
Method call
73
How would we upper case our strings?
>>>word="hello" >>>print(word.upper()) "HELLO"
74
How would we find certain character?
>>>word="apple" >>>hi=word.find("a") >>>print(hi) 0
75
What is the result of the following? >>>word="apple" >>>hello=word.find("l",2) >>>print(hello)
>>>word="apple" >>>hello=word.find("l",2) #having more than one argument is called an optional argument >>>print(hello) 3
76
What is 24.0//3?
8.0
77
What kind of error involves "Maximum recursion depth exceeded error"?
Runtime error