Ch. 7 Flashcards

1
Q

How does the input function work?

A

It pauses your function and waits for the user to enter some text. Once Python receives the user’s input, it assigns that input to a variable to make it convenient for you to work with.

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

What is the code for the input function?

A

variable_name = input(“prompt”)

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

How do you write a prompt that is longer than one line?

A

prompt = “First part of prompt message”
prompt += “\n Second part”

variable_name = input(prompt)

NOTE: += operator takes the string that was assigned to prompt and adds the new string onto the end.

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

What is the modulo operator?

A

%

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

What does the modulo operator do?

A

Divides a number by another number and returns the remainder.

example: 4 % 3
returns: 1

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

What does the while loop do?

A

A while loop runs as long as, or while, a certain condition is true

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

What is a flag?

A

For a program that should run only as long as many conditions are true, you can define one variable that determines whether or not the entire program is active. This variable is called a flag.

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

When do you use the break statement?

A

To exit a while loop immediately without running any remaining code in the loop, regardless of the results of any conditional test.

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

What does the continue statement do?

A

Rather than breaking out of a loop entirely without executing the rest of its code, you can use the continue statement to return to the beginning of the loop based on the result of a conditional test.

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