How Variables work in Python Flashcards

(21 cards)

1
Q

What is a variable?

A

A variable is a container for the value it behaves as the value it contains. Think of variables like in algebra

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

What are boolean variables?

A

True or false

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

How do you create a variable?

A

Every variable needs a unique name.

I.e. name=”Meeko”

*don’t forget the quotation marks. Code will not run if you don’t hit RUN

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

Print a variable name of Kevin.

A

FILE—>NEW—>(name it: Try)–>CLICK PYTHON FILE

NAME=”Kevin”
print (NAME)

Terminal Window: Kevin

*don’t need quotes in PRINT because if you do, the terminal window will display as “Kevin” instead of just Kevin.

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

What is a string?

A

A string is a type of variable that is a series of characters.

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

Create a string literal that reads Goodbye HCS

A

NAME=”HCS”
PRINT(“Goodbye “+name)

Window Terminal: Goodbye HCS

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

How do you check the type of a variable?

A

NAME= “Dog”
PRINT(TYPE(NAME))

TERMINAL WINDOW

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

What is str?

A

Str stands for strings which is a series of characters. it is a data type of a variable.

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

Can you combine variables?

A

Yes you can combine variables as long as they are of the same data type.

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

combine variables to display a printed I love Kevin Wallace

A

FIRST_NAME = “KEVIN”
LAST_NAME = “WALLACE”
FULL_NAME = FIRST_NAME + LAST_NAME
PRINT(“I LOVE “+ FULL_NAME)

T.W.D.: I LOVE KEVINWALLACE

To add a space, go to FULL_NAME = FIRST_NAME +
“ “ + LAST_NAME

T.W.D.: I LOVE KEVIN WALLACE

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

How do I change the variables to a comment data type?

A

Add # in front of each line.

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

What is int?

A

int is another data type known as an integer. An integer is any whole number.

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

What happens if you put an int value in “ “?

A

This changes the variable data type from an int to a str

integer to string, strings cannot be used in a mathematical data types

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

Increase the age of 52 by 4

Use both ways

A
AGE = 52
AGE = 52 +4

TWD: 56

AGE = 52
AGE +=4

TWD: 56

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

Create a code that says Your age is 85 by starting with the original age of 80.

A

AGE = 80
AGE += 5
PRINT (“Your age is: “ + str(age))

TWD: Your age is 85

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

What is a float data type?

A

A float data type is a floating point number. meaning it has a decimal number.

17
Q

Typecast Your height is 152.25 cm

A

HEIGHT= 152.25
PRINT(“YOUR HEIGHT IS: “ + STR(HEIGHT) +” “ +”cm”)

TWD: Your height is 152.25 cm

18
Q

What is a boolean (bool) data type?

A

Boolean data types or bool can only store true or false.

19
Q

Create a code that displays Does Kevin Love Meeko: True

A

ANSWER= True
PRINT(“DOES KEVIN LOVE MEEKO: “ + STR(ANSWER))

TWD Does Kevin love Meeko: True

20
Q

human= false
print (“Are you human: “ + str(human))

TWD error

Why didn’t the code work?

A

For Bool, True or False must have correct uppercase.

fix:
human= False
print (“Are you human: “ + str(human))

TWD Are you human: false

21
Q

What are the 4 basic types of data for Python?

A

Str (strings): stores a series of characters

Int (integer): stores whole numbers

Float (Floating point number): stores decimal numbers

Bool (Boolean): stores True or False for if statements