Ch. 7 Flashcards
How does the input function work?
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.
What is the code for the input function?
variable_name = input(“prompt”)
How do you write a prompt that is longer than one line?
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.
What is the modulo operator?
%
What does the modulo operator do?
Divides a number by another number and returns the remainder.
example: 4 % 3
returns: 1
What does the while loop do?
A while loop runs as long as, or while, a certain condition is true
What is a flag?
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.
When do you use the break statement?
To exit a while loop immediately without running any remaining code in the loop, regardless of the results of any conditional test.
What does the continue statement do?
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.