Python Finals Practice v1 (Whole Doc)

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What will the output be when calling fashionably_late(party_attendees, 'Ford')?

  • Ford is fashionably late
  • Ford was not invited
  • Ford cannot be evaluated
  • Ford is not fashionably late (correct)

What does the my_list.remove('micro') statement do?

  • Removes the first occurrence of 'micro' (correct)
  • Removes all instances of 'micro' from the list
  • Removes the last element of the list
  • Removes the item at index 'micro'

What will happen if you execute del my_list on the list ['stat', 'python', 'marketing']?

  • The list will be cleared
  • An error will occur
  • The list variable will be deleted (correct)
  • The last item will be removed

If we execute list1 = [1, 1, 2, 3, 1] followed by list1.remove(1), what will be the resulting list?

<p>[1, 2, 3, 1] (A)</p> Signup and view all the answers

Which method would you use to count how many times 'python' appears in my_list?

<p>my_list.count('python') (A)</p> Signup and view all the answers

What will be the output of the following code snippet: a = 1; print(a); b = 2; b?

<p>1 (C)</p> Signup and view all the answers

How does the print(f'.....') function interpret variables?

<p>It recognizes variables and uses their values in the output (C)</p> Signup and view all the answers

What is the result of the expression x**2 + x + 1 when $x = 1$?

<p>3 (A)</p> Signup and view all the answers

What will be the output of print('My integer was ' + str(some_integer)) if some_integer = 73?

<p>My integer was 73 (A)</p> Signup and view all the answers

Which method is used to convert numbers into strings for printing purposes?

<p>str() (B)</p> Signup and view all the answers

When using the print function with comma-separated values, how are individual items handled?

<p>They are printed with spaces in between (D)</p> Signup and view all the answers

What does the expression a = 5; print('the value of a is {a}') output?

<p>the value of a is {a} (B)</p> Signup and view all the answers

What will occur if you try to print a float using print('My float was ' + some_float) without converting it to a string?

<p>It will result in an error (D)</p> Signup and view all the answers

What does the function losing_team_captain return?

<p>The name of the captain of the worst team (D)</p> Signup and view all the answers

Which statement correctly explains the purpose of the select_second function?

<p>Returns the second element of a list or None if it doesn't exist (D)</p> Signup and view all the answers

In the function purple_shell, which racer is swapped with the first place racer?

<p>The last place racer (B)</p> Signup and view all the answers

What will the output be if the purple_shell function is called with the input ['Mario', 'Bowser', 'Luigi']?

<p>['Luigi', 'Bowser', 'Mario'] (A)</p> Signup and view all the answers

What is the expected output of select_second(L) where L = [1, 2]?

<p>2 (C)</p> Signup and view all the answers

What is the correct way to append a value to a list in Python?

<p>list.append(value) (B)</p> Signup and view all the answers

What happens if losing_team_captain function is provided an empty list as input?

<p>It raises an IndexError (C)</p> Signup and view all the answers

What will happen if the input to select_second(L) is a single-element list L = [1]?

<p>The function will return None (A)</p> Signup and view all the answers

What is the result of the expression '5 + 3 * 2'?

<p>11 (A)</p> Signup and view all the answers

Which operator is used in Python for floor division?

<p>// (A)</p> Signup and view all the answers

What will be the result of '3 % 2'?

<p>1 (A)</p> Signup and view all the answers

What does the operator '**' represent in Python?

<p>Exponentiation (A)</p> Signup and view all the answers

If t = True and f = False, what is the result of 't and f'?

<p>False (A)</p> Signup and view all the answers

What will the expression 'not(t or f)' evaluate to given t = True and f = False?

<p>False (C)</p> Signup and view all the answers

What is the output of 'print(10 ** 3)'?

<p>1000 (D)</p> Signup and view all the answers

What will be the outcome of '3 // 2'?

<p>1 (D)</p> Signup and view all the answers

What happens to the return type of the built-in function round if ndigits is omitted?

<p>It returns an integer. (D)</p> Signup and view all the answers

What is the primary purpose of a docstring in Python functions?

<p>To provide a description and usage examples. (D)</p> Signup and view all the answers

Which of the following best describes the least_difference function?

<p>Returns the smallest difference between any two of three given numbers. (D)</p> Signup and view all the answers

Which of the following statements is true regarding the help function in Python?

<p>It displays the function signature and a brief description. (B)</p> Signup and view all the answers

What does the >>> symbol in a docstring example indicate?

<p>It indicates a command prompt in Python interactive shells. (B)</p> Signup and view all the answers

What should be the first step in constructing the function mentioned in the exercise?

<p>Define the function with parameters for hours, minutes, and seconds. (A)</p> Signup and view all the answers

In the context provided, why is it important for programmers to use docstrings?

<p>It allows for easier understanding and maintenance of the code. (D)</p> Signup and view all the answers

What will the output be if the least_difference function is called with the arguments (1, 5, -5)?

<p>4 (C)</p> Signup and view all the answers

What will the function 'my_fct(1, 30, 30)' return?

<p>5430 (B)</p> Signup and view all the answers

Which of the following lines of code correctly returns two numbers in increasing order?

<p>return min(a, b), max(a, b) (A)</p> Signup and view all the answers

What does the function 'round_to_two_places(num)' do with the input 3.14159?

<p>Returns 3.14 (A)</p> Signup and view all the answers

What will the output be when executing 'print(1, 2, 3, sep=' < ')'?

<p>1 &lt; 2 &lt; 3 (C)</p> Signup and view all the answers

What will happen if 'greet()' is called without any arguments?

<p>It will print 'Hello, Colin'. (A)</p> Signup and view all the answers

If there are 91 candies and three friends, how many will be smashed according to the function described?

<p>1 (D)</p> Signup and view all the answers

Which statement about default arguments in functions is true?

<p>They can provide flexibility when calling functions. (D)</p> Signup and view all the answers

What will the output be if 'my_fct_2(20, 10)' is called?

<p>(10, 20) (D)</p> Signup and view all the answers

Flashcards

Python arithmetic operators

Python operators for performing basic mathematical calculations (+, -, *, /, //, %, **, -) on numbers.

Integer division (Python)

Results in a float if the quotient is not a whole number.

Floor division (Python)

Result is the whole number part (integer) of the quotient.

Modulo operator (Python)

Returns the remainder after integer division.

Signup and view all the flashcards

Boolean operators (Python)

Used to combine or negate boolean values (True or False) using 'and', 'or', and 'not'.

Signup and view all the flashcards

Print f-string

A way to include variables inside a print statement using curly braces {}. It formats the output.

Signup and view all the flashcards

Logical AND

Returns True only if both operands are True; otherwise False.

Signup and view all the flashcards

Logical OR

Returns True if either operand is True; otherwise False.

Signup and view all the flashcards

Variable in print

Using variables inside a print statement to insert their values. The f-string method is used to include variable values within print statements.

Signup and view all the flashcards

Logical NOT

Reverses the boolean value. True becomes False, and False becomes True.

Signup and view all the flashcards

Casting to string

Converting a variable of a certain data type to a string data type to print it.

Signup and view all the flashcards

Comma separated print

A way to combine text and variables within print statements using commas.

Signup and view all the flashcards

Integer

A whole number (no decimal point).

Signup and view all the flashcards

Float

A number with a decimal point.

Signup and view all the flashcards

Arithmetic operators

Symbols used to perform mathematical operations (+, -, *, /, **).

Signup and view all the flashcards

x**2 + x + 1

Mathematical expression to calculate a value based on the input of variable x.

Signup and view all the flashcards

Fashionably Late

A person who arrives at an event after half the expected guests have arrived.

Signup and view all the flashcards

List's del Method

Removes an item from a list by its index, modifying the original list.

Signup and view all the flashcards

List's remove Method

Removes the first occurrence of a specific item from a list, modifying the original list.

Signup and view all the flashcards

Copying Lists in Python

There are two ways to copy lists: creating a copy that's identical to the original (changes affect both) and creating an independent copy (changes only affect the new copy).

Signup and view all the flashcards

List's count Method

Counts how many times a specific item appears in a list.

Signup and view all the flashcards

Losing Team Captain

The captain (second element) of the worst team in a list of teams.

Signup and view all the flashcards

select_second(L)

Returns the second element of a list, or None if the list has fewer than 2 elements.

Signup and view all the flashcards

purple_shell(racers)

Swaps the first and last place racers in a list.

Signup and view all the flashcards

List of Teams

A list where each element is a list of team members; this usually holds the team members as a list of names. First player is Coach and the second is Captain.

Signup and view all the flashcards

List Append

Adding an item to the end of a list using the append method.

Signup and view all the flashcards

List indexing

Accessing specific elements in a list using their position.

Signup and view all the flashcards

Nested list

A list that contains other lists as its elements.

Signup and view all the flashcards

Method

A function that is associated with a particular object or data type (e.g., list).

Signup and view all the flashcards

Docstring

A special string within a function's code that explains its purpose, arguments, and return values.

Signup and view all the flashcards

Help Function

A built-in Python function (help()) that displays information about a function or module.

Signup and view all the flashcards

Example Function Call

An example of how to use a function with specific arguments in a docstring, often used to illustrate its behavior.

Signup and view all the flashcards

Function Header

The first line of a function definition, including the function name and its parameters, for example, def my_function(x, y):.

Signup and view all the flashcards

Function Docstring Purpose

To explain what a function does and how it works, making it easy to understand and use.

Signup and view all the flashcards

Example Function Call in Docstring

A line in a docstring that shows a specific example of how to call the function, often followed by an expected output, like >>> my_function(5, 2).

Signup and view all the flashcards

Docstring for Built-in Functions

Available through the help() function, providing information about the function's purpose, arguments, and return values.

Signup and view all the flashcards

Docstring Convention

The practice of including a docstring at the beginning of every function, explaining its purpose and usage.

Signup and view all the flashcards

Default argument

An optional argument in a function that takes a default value if not explicitly specified in the function call.

Signup and view all the flashcards

Function with default arguments

A function definition that includes parameters with default values, allowing flexible usage.

Signup and view all the flashcards

How do default arguments work?

When calling a function, if an argument is not provided for a parameter with a default value, the default value is automatically used.

Signup and view all the flashcards

Function with multiple arguments

A function that takes multiple input values, which are then used in the function's logic.

Signup and view all the flashcards

Function with optional arguments

A function that allows the user to provide additional arguments beyond the required ones.

Signup and view all the flashcards

What does return do in a function?

The return statement specifies the output or result value that a function produces.

Signup and view all the flashcards

How to compare two numbers

Using comparison operators like '>' and '<' to determine which number is larger or smaller.

Signup and view all the flashcards

What is the round(num, digits) function?

The round(num, digits) function rounds a given number (num) to a specified number of decimal places (digits)

Signup and view all the flashcards

Study Notes

No Specific Topic Provided

  • Insufficient information to generate study notes. Please provide the text, file, or questions.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Finals Python Documents PDF

More Like This

ICS 33 Final Flashcards
24 questions

ICS 33 Final Flashcards

WellRegardedObsidian1129 avatar
WellRegardedObsidian1129
Use Quizgecko on...
Browser
Browser