python recap Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Choosing which lines of code to execute based on a condition​

Example: ​

A

num = int(input(“Enter a number”))​

if num == 5:​

print(“Correct”)​

else:​

print(“Nope”)

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

For loops

A

for counter in range(5):​

print(“This message prints 5 times”)​

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

​While loops

A

answer = “”​

while answer != “London”:​

answer = input(“What is the capital of England?”)​

—​

num = 1​

while num <= 5:​

print(num)​

num +=1​

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

Used to store multiple data items under a single identifier (variable name)​

Examples: ​

A

emptyList = []​

myList = [“Bananas”, “Apples”, “Pears”]​

myList.append(“Grapes”) ​

numList = [3,6,9,12]​

print(myList)​

print(myList[2])​

print(len(myList))​

myList.remove(“Apples”)​

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

Example Procedure:

A

Subroutines​

def sayHello():​

print(“Hello how are you?”)​

def sayHello(name):​

print(“Hello”, name, “how are you?”)​

sayHello()​

sayHello(“Billy”)

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

Example Function:

A

Subroutines​

def add(num1,num2):​

answer = num1 + num2​

return num2​

answer = add(4,9)​

print(answer)

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