1/37
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
In Python, the _____ function is used to get input from the user
during program execution
input()
The input function will always return the text entered by a user as…
a string
How do you get an integer from user input?
By using type casting/type conversion
What is the code used to convert the string from user input into an integer?
int(input(…))
How does input work?
The input() function pauses your program 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.
The input() function takes one argument: the prompt that we want
to display to the user, so they know what kind of information to
enter. The program waits while the user enters their response and
continues after the user presses ENTER.
How can you write clear prompts?
By adding a space at the end of your input prompt (after a colon) to separate the prompt from the user’s response to make it clear they’re supposed to respond.
How to build multiline prompts?
The first line assigns the first part of the message to the variable prompt. In the second line, the operator += takes the string that was assigned to prompt and adds the new string onto the end.

How do you join/connect strings together?
By using the “+” symbol

What would the shorthand version of the following code be?:
c = 5
result = c + 100
print (result)
c = 5
c += 100
print (c)
To use mathethematical operations on user inputted numbers what must you do?
Change the data type from a string to and integer.
While loop
A loop that runs as long as, or while, a certain condition is true.
Flag
A variable that tells the while loop whether it should keep running or stop.
Break statement
A statement that is used to immediately exit a while loop regardless of the loop’s original condition.
Is the “break” statement exclusive to while loops?
No, it can also be used in for loops.
Continue statement
Returns the program to the beginning of the loop, based on the result of a conditional test.
Dictionary
A collection of key-value pairs
A key-value pair is a set of values associated with each other.
Each key is connected to a value, and you can use a key to access
the value associated with that key.
A key’s value can be a number, a string, a list, or even another
dictionary.
In Python, a dictionary is wrapped in curly braces {} with a series of
key-value pairs inside the braces. Every key is connected to its
value by a colon, and individual key-value pairs are separated by
commas.
You can store as many key-value pairs as you want in a dictionary
user1= {“color”: “green”, “points”: 5, “level”: 3}
mickey= {“name”:”Mickey Mouse”, “age”: 100, “gender”: “male”}
How to access values in a dictionary
Give the name of the dictionary and then place the key inside a set of square brackets

When to use a list
You have ordered data.
You want to access items by position/index.
You need to iterate over items in sequence.
You don’t need to associate values with unique keys.
When to use a dictionary
You want to store key-value pairs.
You need fast lookup by a unique key.
The data is unordered.
You want to associate meaningful labels with values.
How do add new key-value pairs to a list
You can also use this method to modify values in a dictionary

How to remove key-value pairs in a dictionary

.get() method
This method requires a key as a first argument. As a second optional argument, you can pass the value to be returned if the key doesn’t exist.
If you leave out the second argument in the call and the key doesn’t
exist, Python will return the value None. The special value None means “no
value exists.” This is not an error: it’s a special value meant to indicate the
absence of a value
Looping with dictionaries
To write a for loop for a _______, you create names for the two variables that will hold the key and value in each key-value pair.
What method would you use if you only want to loop through the keys of the dictionary?
.keys()
You can also use this method to check if an item is not in the dictionary

Functions
Blocks of code designed to do one specific job.
When you want to perform a particular task that you’ve defined in a function, you call the ______ responsible for it.
• If you have a task that needs to be done multiple times in different parts of your program, you don’t need to write the same code again and again. You can simply call the _____ designed to handle that task, and Python will execute the code inside the ______.
Function Parameter
The variable defined in the function header. It’s a part of the function definition.
Function Argument
The actual value you pass into the function when you call it.
Keyword Arguments
A name-value pair that you pass to a function. You directly associate the name and the value within the argument,
so when you pass the argument to the function, there’s no
confusion.
Can you assign a default value for a parameter?
Yes
Return Value
The return statement takes a value from inside a function and
sends it back to the line that called the function.
A function can return any kind of value you need it to, including
more complicated data structures like lists and dictionaries.
True
Advantages of storing functions in separate files
Storing your functions in a separate file allows you to hide the details of your program’s code and focus on its higher-level logic.
It also allows you to reuse functions in many different programs. When you store your functions in separate files, you can share those files with other programmers without having to share your entire program.
Knowing how to import functions also allows you to use libraries of functions that other programmers have written.
What is a path?
The exact location of a file or folder on a system.
Relative File Path
Tells Python to look for a given location relative to the directory where the currently running program file is stored.
Absolute File Path
Tells Python exactly where the file is on your computer, regardless of where the program that’s being executed is stored.
Exceptions
Used to manage errors that arise in program execution
Handled with try-except blocks
Algorithm
step-by-step procedure or set of instructions designed to perform a specific task or solve a particular problem.
Recursion
A technique by which a method makes one or more calls to itself during execution, or by which a data structure relies upon smaller instances of the very same type of structure in its
representation.