Ask Question
6 November, 18:33

Define a Python function named low_rent that two parameters. The first parameter will be a list. Each entry in the first parameter is also a list of 3 values representing the following fields: State Code, MedianEfficiencyRent, Area Name The first and last of these will be strs and the middle one is a float The second parameter will be a string specifying the CSV file you must append. For each entry in the first parameter, if the median rent of an efficiency (e. g. value at index 1) is less than 576, write the entry as three columns in the CSV file. You do not need to do anything when the median rent of an efficiency is 576 or higher. Examples:low_rent ([], "empty. csv") appends a file named empty. txt but does not add any data.

low_rent ([ ["NY", 603.0, "Cayuga County, NY"], ["AR", 410.0, "Sevier County"] ], "a. csv") adds the row AR, 410.0, Sevier County at the end of the a. csv file.

+4
Answers (1)
  1. 6 November, 18:57
    0
    def low_rent (list, file) : #defining the function

    with open (file,'w') as file: #opening the filename with write mode

    comma=',' #defining the variable comma to join the list

    for i in range (len (list)) : #iterating over the list

    if (list[i][1]) <576: #checking if value at index 1 is less than 576

    final_list=[str (i) for i in list[i]] #making all the arguments in list as stirngs

    string=comma. join (final_list) #jointing the list with comma

    file. write (string) #writing the final string to the file

    low_rent ([["NY", 603.0, "Cayuga County, NY"],["AR", 410.0, "Sevier County"]],'a. csv')

    #call the function
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Define a Python function named low_rent that two parameters. The first parameter will be a list. Each entry in the first parameter is also ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers