Chapter one Flashcards

1
Q

Run python and get it to display hello world

Do it via file as well

A

cmd
python
print(“Hello, World”)

new file
print(“hello world”)
save as hello.py
click run
start debugging
python

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

What is the term print known as?

A

A function

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

Create a variable called name, ask “what is your name?” and allow it to be input
Next, have the program say hello to you

A

name = input(“what is your name?” )
Space is intentional at end!
print (“Hello, “ + name”)

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

What do you call it when text is added to a variable
Like when your name is added to the name variable?

A

It’s a string

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

Create two variables and print them

What are the three ways to add spaces to the output so the variables aren’t together?

A

word1 = “hello “
word2 = “world
print(word1 + word2)

print(word1 + “ “ + word2)

or
space = “ “
print(word1 + space + word2)

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

Give some examples of slicing

A

greeting = “Well, hello there!”
hello = [6:11]
print(hello)

or just
print(greeting[6:11])

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

Via slicing, describe what this means: [6:11]

A

Everything after 6 up to and including 11

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

What would these two do in terms of slicing
[:11]
[6:]

A

[:11] - From the beginning up to and including 11

[6:] - From after 6 to the end of the string

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

What would these be called in python
3
3.1

A

3 - interger
3.1 - floating point number / float for short

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

Create a program that takes the price of coffee that you input and gives you your total for everything

A

price = input(“What is the price of a cup of coffee? “)
cups = input(“How many cups do you want? “)
total = float(price) * int(cups)
print(“Your total is $” + str(total) + “ for “ + cups + “ cups”)

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

How do you tell python that you’re creating a float, string, and interger

A

float(variable)
int(variable)
str(variable)

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

What do you call it when you change something from a certain type like an interger, float, or string to another type

A

casting
In the end we are casting the total as a string

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

Cast numbers from price and cups into another variable

A

price = input(“Price? “)
cup = input(“Cups? “)
total_price = float(price)
total_cup = int(cup)

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

How would you create a comment?

A

#

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

What is a newline and how do you create one

A

newline is a break
once you print something to the console it will automatically add one, but if you want to do it manually in the middle of your string, add \n like this:

print(“Hello,\nWorld”)
do two to add two breaks
print(“Hello, World\n\nHello, World”)

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

Create a list and display something from it

A

grocery_list = [“fruit”, “milk”, “juice”, “hamburger”]
number = [1, 2, 3, 4]
print(“I need to buy “ + number[1] + grocery_list[0])

17
Q

what is the number called in the following list:
grocery_list[1]

A

index

18
Q

Create a tuple and explain why it is immutable

A

planets = (“Mercury”, “Venus”, “Earth”, “Mars”, “Jupiter”, “Saturn”, “Uranus”, “Neptune”)

A tuple is immutable which means its values can’t change unlike a list. This is faster and better for the security of a program if needed.

19
Q

Explain a set, make one, and show a neat way to organize it (you can do the same with tuples and lists

A

Sets delete duplicates and are contained in curly brackets
cool_dudes = {
“James Randy”,
“Bill Bundy”,
“Jim Jimmerson”,
“Derick Dondre”
}
Don’t forget your tab in between entries

20
Q

What does mutable mean?

A

editable

21
Q

Define a dictionary and then create one
Print only one of the keys for the screen.

A

Dictionaries cannot contain duplicates and also feature “key:value pairs”

customer1 = {
“name”: “Robert Cow”,
“occupation”: “Fart Worshiper”
“age”: 30,
“phone”: “812-888-8888”
}

print(customer1[“name”])

22
Q

Describe a boolean and then create one

A

Booleans can either be True or False
Answer1 = True
Answer2 = False

23
Q

create a multidimensional list, and then print a particular entry in one

A

list = [
[
[23, 45],
[82, 12]
]
[
[34, 18],
[41, 91]
]
]
print(list[1][1][0]

24
Q
A