Question

Use the Design Recipe to define a function save_history which consumes two parameters, a nested list and an int representing the current landing attempt. The function should open a new file named LandingNN.csv where NN is two digits representing the current landing attempt. The first line should contain the number of sublists in the nested list. Each sublists should be written to the file on its own line with its values separated by commas. This function should close the file when its finished writing to it. Include a docstring! For example: contents of file Landing01.csv Test 4 history - 13.61, 2.98, 15, 0], [3.01, 0.6, 14, 1], [0.79, 2.22, 14, 0], o, 3.84, 14, 2]].61,2.9815,0 saseonystorythtstorysj 15. e]. 3.01, 0.6, 14, 1. [0.79, 2.22, 14,°]. CO, 3.84, 14, 21 3.01,0.6,14,1 0.79,2.22,14,0 0,3.85,14,2 Note: When running your code, you can call the pre-defined function show-file contents(filename) to view the contents of the file you saved. For example to view the contents of Landing01.csv use this statement: show_file_contents (Landing01.csv)

Python Language !

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ㅑ save history.py-D:/Coding/PYTHON/save history.py (3.6.2) File Edit Format Run Options Window Help def save history (nl,a):

OUTPUT :

RESTART: D:/Coding/PYTHON/save history.py >>> save history (I[1,2],13,41,15, 611,15) RESTART: D:/Coding/PYTHON/save history.p

CODE :

def save_history(nl,a):
    #Form the file name
    name = 'Landing'
    if a<10:
        name = name+'0'+str(a)+'.csv'
    else:
        name = name+str(a)+'.csv'
    #Length of the list
    s = len(nl)
    f = open(name,'w')
    #Write the list length
    f.write(str(s)+'\n')
    #For all the lists, add it to the file
    for lst in nl:
        f.write(','.join([str(x) for x in lst])+'\n')
    f.flush()
    f.close()

Add a comment
Know the answer?
Add Answer to:
Python Language ! Use the Design Recipe to define a function save_history which consumes two parameters,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Language The Blip Blob New Year celebration started on a Tuesday. Use the Design Recipe...

    Python Language The Blip Blob New Year celebration started on a Tuesday. Use the Design Recipe to write a function called blip_blop_day that consumes an int representing the number of days that have passed since their celebration start day and returns name of the current day. For example, if 2 days have passed, then 'Thursday' should be returned. Include a docstring! For example: Test Result 2 Thursday 4 Saturday Monday Tuesday 6 7 8 Wednesday

  • Problem 20 [ 2 points ] Use the Design Recipe to write a function, print_histogram that...

    Problem 20 [ 2 points ] Use the Design Recipe to write a function, print_histogram that consumes a list of numbers and prints a histogram graph using asterisks to represent each number in the list. Use one output line per number in the list. You may assume that only integers are passed to this function. Your function should ignore negative values. Include a docstring! Test Result print_histogram([ 0, 2, 4, 1]) ** **** * print_histogram([10, 5, 3, -1, 8]) **********...

  • python program please Write a function called backwards which takes two parameters. The first is a...

    python program please Write a function called backwards which takes two parameters. The first is a file object that has already been opened in read mode called essayfile. The second is called filename, which contains the filename for the output file that will need to be properly opened and closed in your function. The function should read from already opened file object line by line. Each line in the file should have the words on the line reversed. For example,...

  • using python The following shows the result of calling function read_from_file_sum_squares() for each of these two...

    using python The following shows the result of calling function read_from_file_sum_squares() for each of these two files: >>> from praco import read_from_file_sum_squares >>> read_from_file_sum_squares () Enter the filename: file1 9 >>> read_from_file_sum_squares () Enter the filename: file2 14 20 1 >>> You can use file = open(filename, "r") to open the file named by string filename to read, and the line list_lines = file.readlines() to store in list_lines the list of strings, where each string is a line of the...

  • Basic Python code needed Define the get_lines_from_file) function which is passed a filename as a parameter....

    Basic Python code needed Define the get_lines_from_file) function which is passed a filename as a parameter. The function reads the information from the file (corresponding to the filename parameter) and returns a list of strings where each element of the returned list corresponds to one line of the file. The list of strings which is returned by the function should not contain any newline characters. For example, if the file contains the text: 10 440 240 4 42 4 42...

  • Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create...

    Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create a completed program that prompts the user for the name of a data file, and reads the contents of that data file, then creates variables in a form suitable for computing the answer to some questions. The format should be in the same manner as the attached .py file. All subsequent assignment details (.py and .csv files) can be found at this...

  • Python coding exercise: please include comments Goal #1: import financial data given into your pr...

    Python coding exercise: please include comments Goal #1: import financial data given into your program provided to you as a CSV formatted text file Use the following data for testing (the following is only a sample of the data; there are over 4000 rows of data): *Note: The data you will read in is linear by date (but, non-contiguous due to holidays and weekends,) reflecting a timeline of stock performance in chronological order; however your program should run through the...

  • I am stuck with this coding problem from edx coding python 4.4.6: #This is a long...

    I am stuck with this coding problem from edx coding python 4.4.6: #This is a long one -- our answer is 20 lines of code, but #yours will probably be longer. That's because it's one of the #more authentic problems we've done so far. This is a real #problem you'll start to face if you want to start creating #useful programs. # #One of the reasons that filetypes work is that everyone #agrees how they are structured. A ".png" file,...

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

  • Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elemen...

    Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT