Untitled Quiz
23 Questions
0 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 be the output of the following code? total = 0 for count in [1,2,3]: total = total + count print(total)

  • 6 (correct)
  • 5
  • 1
  • 1 4
  • Which of the following correctly describes a list in Python?

  • A comma-separated sequence of data items enclosed in square brackets. (correct)
  • A collection of items that prevents duplicates.
  • A variable holding a single value.
  • A sequence of items enclosed in curly braces.
  • What does the following code return? def pass_it(x, y): z = str(x) + ", " + str(y) answer = pass_it(4, 8) print(answer)

  • 48
  • None (correct)
  • 8, 4
  • 4, 8
  • What is the valid index for extracting 'New York' from the string: city = 'New York city'?

    <p>All of the above</p> Signup and view all the answers

    In Python, what will the expression phones['John'] evaluate to after this code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = '5556666'

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

    Which of the following statements about dictionaries is true?

    <p>Dictionaries are not indexed by number.</p> Signup and view all the answers

    What is the correct way to read data from the keyboard in Python?

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

    What will happen if line 1 is removed, and 'divTags' is replaced with 'soup' in lines 2 and 3?

    <p>The program will still produce the same dataframe df.</p> Signup and view all the answers

    What is the purpose of the 'try' and 'except' block in the error handling code?

    <p>To append 'NA' if a description does not exist.</p> Signup and view all the answers

    What will the print statement inside the 'for' loop located at line 6 display?

    <p>The tag objects for each food item.</p> Signup and view all the answers

    What is the outcome of the provided code snippet that extracts the first tag?

    <p>It will not find any tag due to the wrong attribute name.</p> Signup and view all the answers

    Given the URL format for searching on Amazon, which aspect needs to change to create a search link for 'data science'?

    <p>Only the keyword after '?k=' should change.</p> Signup and view all the answers

    How does the 'p.get_text().strip()' function assist in data cleaning?

    <p>It removes unnecessary whitespace from the content.</p> Signup and view all the answers

    Why might a data scientist use a loop to create search URLs for Amazon?

    <p>To generate a unique URL for each search term systematically.</p> Signup and view all the answers

    What will the variable 'data1' store after lines 4 to 11 are executed?

    <p>A dictionary with food and descriptions as keys.</p> Signup and view all the answers

    Which code correctly extracts the value of the class attribute of all the

    tags in the given html_code?

    <p>for p in soup.find('div').find_all('p'): print(p.attrs['class'])</p> Signup and view all the answers

    What is the output of the code 'soup.find_all(class_="food", limit=1)' in relation to extracting

    tags?

    <p>It retrieves the first <p> tag with class equal to 'food'.</p> Signup and view all the answers

    Which statement is true about 'soup.find('h1', id="top", class="food")'?

    <p>It retrieves the <h1> tag if id is 'top' and class is 'food'.</p> Signup and view all the answers

    How many

    tags will 'soup.body.find_all("p", recursive=False)' return?

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

    What does the code 'soup.find_all("p", string="Cauliflower Fritters")' do?

    <p>It retrieves <p> tags with 'Cauliflower Fritters' as their string content.</p> Signup and view all the answers

    Which code does not print the

    tag object that contains 'Cauliflower Fritters'?

    <p>soup.find_all(class_='food', limit=1)</p> Signup and view all the answers

    What is the expected output from 'print(soup.find("h1", attrs ={ "id":"top" ,"class":"sister" }))'?

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

    Which of these statements describes the structure of the HTML provided?

    <p>The HTML includes <h1>, <p>, and <div> tags collectively.</p> Signup and view all the answers

    Study Notes

    True or False Questions

    • Math expressions in Python are not always evaluated from left to right. They follow operator precedence rules.
    • Repeating operations in Python use loops.
    • Python supports multiple arguments.
    • Code snippet displaying "yes + no" is incorrect.
    • Code checking if choice is not 10 is correct.

    Multiple Choice Questions

    • The input() function gets input from the keyboard.
    • input() returns a string.
    • Output of print(valuel * value2) is 24.0 , given valuel = 2.0 and value2 = 12.
    • A comma-separated sequence of data items enclosed in square brackets is a list.
    • Output of total = 0; for count in [1, 2, 3]: total = total + count; print(total) is 6.
    • Output of def pass_it(x, y): z = str(x) + ", " + str(y); num1 = 4; num2 = 8; answer = pass_it(num1, num2); print(answer) is "4, 8".
    • Valid index values for extracting 'New York' from 'New York city' include 0:8, :8, and 0:-5.
    • Dictionaries are not indexed by number.
    • Output of phones = {'John':'5555555','Julie':'5557777'}; phones['John']='5556666'; print(phones) is {'John':'5556666','Julie':'5557777'}.

    Studying That Suits You

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

    Quiz Team

    Related Documents

    More Like This

    Untitled Quiz
    6 questions

    Untitled Quiz

    AdoredHealing avatar
    AdoredHealing
    Untitled Quiz
    37 questions

    Untitled Quiz

    WellReceivedSquirrel7948 avatar
    WellReceivedSquirrel7948
    Untitled Quiz
    19 questions

    Untitled Quiz

    TalentedFantasy1640 avatar
    TalentedFantasy1640
    Untitled Quiz
    18 questions

    Untitled Quiz

    RighteousIguana avatar
    RighteousIguana
    Use Quizgecko on...
    Browser
    Browser