Python Finals Practice v1 (Whole Doc)
45 Questions
2 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

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]</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')</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</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</p> Signup and view all the answers

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

    <p>3</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</p> Signup and view all the answers

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

    <p>str()</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</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}</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</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</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</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</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']</p> Signup and view all the answers

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

    <p>2</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)</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</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</p> Signup and view all the answers

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

    <p>11</p> Signup and view all the answers

    Which operator is used in Python for floor division?

    <p>//</p> Signup and view all the answers

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

    <p>1</p> Signup and view all the answers

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

    <p>Exponentiation</p> Signup and view all the answers

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

    <p>False</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</p> Signup and view all the answers

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

    <p>1000</p> Signup and view all the answers

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

    <p>1</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.</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.</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.</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.</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.</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.</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.</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</p> Signup and view all the answers

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

    <p>5430</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)</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</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</p> Signup and view all the answers

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

    <p>It will print 'Hello, Colin'.</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</p> Signup and view all the answers

    Which statement about default arguments in functions is true?

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

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

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

    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