Python Basics Flashcards

1
Q

Variable Names
What do computers use variables for?

A

To remember informaion

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

Variable Names
To create a variable, we start by typing it name. Variable names need to be single words and therefore have no spaces.

A

city

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

Variable Names
If we want a variable name with multiple words, we use snake case. Snake case means using _ to connect the additional words.

A

home_city

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

Variable Names
What’s wrong with this variable name?
high score

A

There is a space between the words.

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

Variable Names
To help us understand what’s inside a variable we pick descriptive names.

A

home_city_province

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

Variable Names
What do we use snake case for?

A

To create variable names with multiple words.

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

Updating Variables
Why do we give variables descriptive names like city or population instead of c or p?

A

To help us understand what’s inside them.

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

Expressions
We can add string values together with a + sign

A

“Followers:” + “55”

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

Expressions
We call adding string values and expression as the output creates a single value.
In this example, only oh string is displayed output when we add “55” inside print().

A

print(“Followers:” + “55”)
Followers:55

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

Expressions
When expressions contain variables, they use the values in the variables, which we can see when adding “Followers:” to followers.

A

followers = “55”
print (“Followers:”+followers)

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

Expressions
Since expressions become values, we can store them in variables the same way as values.
See the example her where we’ll code label to display the expression.

A

label = “Posts:” + “13”
print(label)
Posts:13

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

Expressions
What’s the value of label?
label = “Name:” + “Joe”

A

“Name:Joe”

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

Expressions
What does the code display in the console?
user = “snoopdogg”
print(“Username:” + user)

A

Username:snoopdogg

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

Expressions
Add temperature variable to the expression.
temperature = “14”
print(temperature + “ degrees”

A

14 degrees

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

Expressions
Display Posts:55 in the console

A

Print (“Posts:” + “55”)
Posts:55

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

Expressions
Display Ms. Irene in the console
title = “Ms. “
name = “Irene”

A

print(title + name)
Ms. Irene

17
Q

Expressions
Code the string value “likes” so that the code displays 40 likes.

A

number_of_likes = “40 “
print(number_of_likes + “likes”)
40 likes

18
Q

Numbers
We’ve seen before that variables can also store numbers. Unlike strings, numeric values don’t use quotes “”

A

active_users = 5

19
Q

Numbers
We can create expressions with numbers, too. Here, we can add numbers together with + 1

A

number_of_applications = 5 + 1
print(number_of_applications)
6

20
Q

Numbers
We use the * sign to multiply numbers and the / sign to divide numbers. We’ll turn 0.5 into its percent value by multiplying it by 100.

A

percent = 0.5 * 100
print(percent)
50.0

21
Q

Numbers
We can use variables with numbers for calculations, too. We’ll see it in action by adding 1 to number_of_steps.

A

number_of_steps = 70
print(“You’re on step:”)
print(number_of_steps + 1)
You’re on step:
71

22
Q

Numbers
Since expressions become values, we can store calculation results in variables, like her where total contains private + public.

A

private = 3
public = 10
total = private + public
print(“Total posts:”)
print(total)
Total posts:
13

23
Q

Numbers
What’s the value of speed?
speed = 300 + 5

A

305

24
Q

Numbers
Why does this code display 31 instead of 4 in the console?
temperature = “3” + “1”
print(temperature)

A

31
Because “3” and “1” are string values

25
Q

Numbers
How do we know that the score variable stores a number?
score = 40 + 4

A

Because there are no double quotes around 40 and 4

26
Q

Numbers
What does the code display in the console?
area = “3 * 5”
print (area)

A

3 * 5

27
Q

Numbers
Multiply the savings variable by the interest variable.

A

savings = 100
interest = 0.04
print (savings * interest)
4.0

28
Q

Numbers
Divide sum_of_grades by students to get the average grade of a class.

A

sum_of_grades = 460
students = 5
print(sum_of_grades / students)
92.0

29
Q

Numbers
Subtract discount from total and display the calculation result in the console.

A

total = 100
discount = 20
print(“Discounted price:”
print(total - discount)
Discount price:
80

30
Q

Set months_per_year to 12

A

months_per_year = 12
print(months_per_year)
12