Midterm review Flashcards

Zoom!!

1
Q

Variables

A

a bucket to store information in

ex) camelCase or snake_case

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

Integers

A

int

3 or -1 or 0 or 2001

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

Real Numbers

A

float

3.14 or 0.094 or -12.0

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

Character Strings

A

str

“Hi” “ “ “a” “44”

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

Boolean

A

bool

True or False

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

What is this? 3 != 3

A

boolean bc it’s a comparison

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

What is this? “Exam, Day, Soon”

A

string

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

What is this? 5.9

A

float

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

What is this? 2

A

integer

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

What is this? 5.9 - 3

A

float

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

What is this? 9 // 1

A

integer ( just 9 divided by 1)

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

What is this? 5.9 x 3

A

float

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

Concatenation

A
  • fancy name for string
  • has “ “ or ‘ ‘
  • concatenate by +
    • like gluing strings
      together (no spaces)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a method?

A
  • function or command
  • “called” with parenthesis
  • to access method, use dot.operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the two parts of a string?

A

it’s data and it’s methods

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

s = “panang Curry”
method = upper()
print(s.upper())
output?

A

PANANG CURRY

uppercase version of string

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

s = “panang Curry”
method = lower()
print(s.lower())
output?

A

panang curry

lowercase version of string

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

s = “panang Curry”
method = swapcase()
print(s.swapcase())
output?

A

PANANG cURRY

case of each letter is switched

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

s = “panang Curry”
method = capitalize()
print(s.capitalize())
output?

A

Panang curry

1st letter capitalized and the rest are lowercase

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

s = “panang Curry”
method = title()
print(s.title())
output?

A

Panang Curry

first letter of each word is caps and rest is lowercase

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

How do you display:

She said “You need escape characters”
Which are: \important\

A

print(“She said "You need escape characters"” \nWhich are: \important\”

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

Which escape character lets you use double quotes in a string?

A

"

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

Which escape character lets you move to a new line?

A

\n

24
Q

Which escape character allows you to include backslash in output?

A

\

25
Q

Which escape characters allow for indents in strings?

A

\t

26
Q

User input

A
  • store input IN VARIABLE
  • ALWAYS returns a string

ex) num = input(“Enter a number: “) # num is string

input(“Enter a number: “) # useless

27
Q

Branching

A
  • CONDITION that evaluates whether a boolean is true or false
  • mutually exclusive
  • only ONE statement will run
  • multiple ifs = each if statement can potentially run depending on statement
28
Q

if CONDITION

A
  • # do something
  • only need if statement, doesn’t need elif or else
29
Q

elif CONDITION

A
  • # do something
  • NEEDS if statement
30
Q

else:

A
  • # do something
  • NEEDS if statement
31
Q

= vs ==

A

= used for assigning var to new value
== used in your condition for comparison in if statements and while loops– evaluates to true false

ex) var = 3
print(3==3) TRUE

32
Q

What’s the error in this branching example?

name = input(“What’s your name”)
if name == “Kyle” or “Beth”:
print(“Please come in”)

A

name = input(“What’s your name: “)

everything has an associated truth value
e.g.
non-empty string = True
non-zero number = True
non-empty list = True

so “Beth” evaluates to True always

33
Q

Tracing if-statements

x = 10
if x > 3 and x % 2 == 0:
print(“Success”)
else:
print(“Fail”)

1) What will get printed?
2) What values of x will print “Success”?

A

1) print(“Success”)
2) x = 10

33
Q

While loop

A
  • Repeat code without writing repeated cote
  • Great for when you r loop should break: “I wan to loop until the user inputs’q’”
    • while userinput !=’q’
34
Q

For Loop

A
  • for each loop
    • for char in
      “abcdefghijklmno”
  • Range loop
    • for i in range(start, stop,
      step)
    • for num in range(1)
    • for num in range(0,10)
    • for num in range(0,10,1)
35
Q

List and strings are SEQUENCES

A
  • accessing individual elements
  • indices start at 0
    • string example
    • name= “jenny”
    • list example
    • name= [“jenny”, “bob”,
      “tina”]
35
Q

List

A
  • a collection of items
  • create a new list using list() or [ ]
  • are mutable
36
Q

someList.append(value)

A

adds value to end of a list

37
Q

someList.remove9vale)

A

Removes the first occurrence of value from the list

38
Q

List slicing

A
  • used for getting a subset of a list
  • list slicing returns another list
  • specify range of indices
    • someList[start:end]
39
Q

items = [“shirt”, “shoes
, “pants”, “hat”, “socks”, “tank top”]
print(items[2:5])

What gets printed?

*hint– first item of a list always starts with the number 0

A

hat socks

40
Q

split( ) and join ()

A
  • split turns a string into a list
  • join turns a list into a string

charList = excelRow.split(“,”)
newString = “.”join(someList)

41
Q

1 items = [“shirt

A
41
Q
A
42
Q
A
43
Q
A
44
Q
A
44
Q
A
45
Q
A
46
Q
A
47
Q
A
48
Q
A
49
Q
A
50
Q
A
51
Q
A