Compsci Final Study Guid

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

38 Terms

1
New cards


In Python, the _____ function is used to get input from the user

during program execution

input()

2
New cards

The input function will always return the text entered by a user as…

a string

3
New cards

How do you get an integer from user input?

By using type casting/type conversion

4
New cards

What is the code used to convert the string from user input into an integer?

int(input(…))

5
New cards

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.

6
New cards

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.

7
New cards

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.

<p><span><span>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.</span></span></p>
8
New cards

How do you join/connect strings together?

By using the “+” symbol

<p>By using the  “+” symbol</p>
9
New cards

What would the shorthand version of the following code be?:

c = 5

result = c + 100

print (result)

c = 5

c += 100

print (c)

10
New cards

To use mathethematical operations on user inputted numbers what must you do?

Change the data type from a string to and integer.

11
New cards

While loop

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

12
New cards

Flag

A variable that tells the while loop whether it should keep running or stop.

13
New cards

Break statement

A statement that is used to immediately exit a while loop regardless of the loop’s original condition.

14
New cards

Is the “break” statement exclusive to while loops?

No, it can also be used in for loops.

15
New cards

Continue statement

Returns the program to the beginning of the loop, based on the result of a conditional test.

16
New cards

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”}

17
New cards

How to access values in a dictionary

Give the name of the dictionary and then place the key inside a set of square brackets

<p><span><span>Give the name of the dictionary and then place the key inside a set of square brackets</span></span></p>
18
New cards

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.

19
New cards

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.

20
New cards

How do add new key-value pairs to a list

  • You can also use this method to modify values in a dictionary

<ul><li><p>You can also use this method to modify values in a dictionary</p></li></ul><p></p>
21
New cards

How to remove key-value pairs in a dictionary

knowt flashcard image
22
New cards

.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

23
New cards

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.

24
New cards

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

<p>.keys()</p><ul><li><p>You can also use this method to check if an item is not in the dictionary</p></li></ul><p></p>
25
New cards

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 ______.

26
New cards

Function Parameter

The variable defined in the function header. It’s a part of the function definition.

27
New cards

Function Argument

The actual value you pass into the function when you call it.

28
New cards

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.

29
New cards

Can you assign a default value for a parameter?

Yes

30
New cards

Return Value

The return statement takes a value from inside a function and
sends it back to the line that called the function.

31
New cards

A function can return any kind of value you need it to, including
more complicated data structures like lists and dictionaries.

True

32
New cards

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.

33
New cards

What is a path?

The exact location of a file or folder on a system.

34
New cards

Relative File Path

Tells Python to look for a given location relative to the directory where the currently running program file is stored.

35
New cards

Absolute File Path

Tells Python exactly where the file is on your computer, regardless of where the program that’s being executed is stored.

36
New cards

Exceptions

Used to manage errors that arise in program execution

Handled with try-except blocks

37
New cards

Algorithm

step-by-step procedure or set of instructions designed to perform a specific task or solve a particular problem.

38
New cards

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.