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
  • CODE IN PYTHON 17. Use the Design Recipe to define a function called  black_jack  which consumes to 2...

    CODE IN PYTHON 17. Use the Design Recipe to define a function called  black_jack  which consumes to 2 int values greater than 0. Return whichever value is nearest to 21 without going over. Return 0 if they both go over. Include a docstring! Write three assertEqual statements to test your function.

  • 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]) **********...

  • 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...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

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