Values and Variable Flashcards

You may prefer our related Brainscape-certified 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
Q

Define expression

A

A combination of values, variables and operators

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

Define statement

A

A unit of code that has an effect like creating a variable or displaying a value

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

What does a newline look like?

A

\n

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

What is an example of a strongly-typed high level language?

A

C or C++

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

What is an example of a weakly-type high level language?

A

Python

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

What does GPS stand for in programming?

A

Good programming style

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

Define weakly-type high level language

A

You can store any value in a variable

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

Define strongly-type high level language

A

Must state the type of value before assigning a variable with a value.

32
Q

What is the advantage of strongly-type high-level language versus weakly-type?

A

Weakly-type high level language are error-prone

33
Q

Does Python automatically follow order of operations?

A

Yes

34
Q

What does this symbol # mean in programming and what is its purpose?

A

means comments and it is good for explaining what the program does

35
Q

Define concatenate

A

To join two operands end-to-end

36
Q

Define exception

A

An error that is detected while the program is running

37
Q

Define semantics

A

Meanings of a program

38
Q

Define semantic error

A

An error within the program that makes it do something other than what the programmer intended

39
Q

What is the symbol for floor division and what does it do?

A

// is the symbol for floor division l and rounds the number into an integer.

40
Q

What is the symbol for modulus and what does it do?

A

% is the symbol for modulus and it divides two numbers and shows the remainder. Ex. 105%60 = 45

41
Q

Define hand trace

A

Predicting the results of our code without the use of computer

42
Q

What are 6 categories of statement?

A
Assignment statement
Input statement 
Output statement 
Operational statement 
Iterate statement 
Conditional statement
43
Q

True or false? Prompt must be a string

A

True

44
Q

What are three conversion functions?

A

Int()
Float()
Str()

45
Q

Define operand

A

Number being used in a operation

46
Q

What does the built-in function look like for assignment statement?

A

Variable=value

47
Q

Define argument

A

Data we want the function to use and act upon

48
Q

What does the built-in function look like for input statement?

A

Input (prompt)

49
Q

What does the built-in function look like for output statement?

A

Print (argument)

50
Q

What does the built-in function look like for operational statement?

A

(Operand)(operator)(operand)

51
Q

Which is a literal value?

A= 7

A

7

52
Q

What are three type of errors?

A
  • Syntax error
  • Runtime error
  • Semantic error
53
Q

What is a Syntax error

A

Occurs when our Python code does not follow the Syntax rule

54
Q

What is the runtime error?

A

Occurs when the user enters an invalid test data

55
Q

What are two things that the test case contains?

A
  • Test data: specific values

- Expected result: must be computed beforehand

56
Q

Define returned values

A

When a function returns a result and that result is called a return value.

57
Q

Define string concatenation

A

Joins strings by adding or linking them end-to-end.
Example:&raquo_space;>”first”+”second”
“Firstsecond”

58
Q

What is the result of this function and what is it called?

|&raquo_space;>”hi” * 3

A

“hihihi”

String repetition

59
Q

What does an index look like and what does it indicate?

A

[] expression in brackets. It indicates which character in the sequence you want

60
Q

Define string

A

It is a sequence of character

61
Q

What will happen as a result of this function and what is it called?
»>fruit=banana
»>letter=fruit[1]

A

> > > letter=fruit[1]
“a”
B in banana is considered the 0th letter while A is considered the 1st

Function called an index

62
Q

What will happen as a result of this function and what is it called?
»>fruit=banana
»>letter=fruit[0]

A

> > > letter=fruit[0]
“b”

Function called an index

63
Q

True or false? Index can be any number

A

False. Index must be an integer.

64
Q

Define lens

A

Built-in function that returns the number of characters in a string

Ex.&raquo_space;>fruit=”apple”
»>len(fruit)
5

65
Q

What is the result of the following and what is the function called?

> > > word= hi
len(word)

A

> > > word= hi
len(word)
2

Len function

66
Q

Define slice

A

A segment of a string

Example:&raquo_space;> a=”apple”
»>a[0:2]
“Ap”

67
Q

What will happen to the following and what is it called?

> > > a=”apple”
a[:2]

A

“Ap”

String slicing

68
Q

What will happen to the following and what is it called?

> > > a=”apple”
a[2:]

A

“ple”

String slicing

69
Q

Define empty string

A

When first string index is greater or equal to the second index

70
Q

What will happen to the following and what is it called?

Ex.&raquo_space;> a=apple
»>a[3:3]

A

” “

Empty string

71
Q

What will happen to the following and what is it called?

Ex.&raquo_space;> a=apple
»>a[6:3]

A

” “

Empty string

72
Q

Define invocation

A

Method call

73
Q

How would we upper case our strings?

A

> > > word=”hello”
print(word.upper())
“HELLO”

74
Q

How would we find certain character?

A

> > > word=”apple”
hi=word.find(“a”)
print(hi)
0

75
Q

What is the result of the following?
»>word=”apple”
»>hello=word.find(“l”,2)
»>print(hello)

A

> > > word=”apple”
hello=word.find(“l”,2) #having more than one argument is called an optional argument
print(hello)
3

76
Q

What is 24.0//3?

A

8.0

77
Q

What kind of error involves “Maximum recursion depth exceeded error”?

A

Runtime error