Question: https://github.comoahwaterfieldprice/python_primer/tree/master/ch_6 = Used this for help, but is too old for python 3.7 3 Functions and branching the sun in light years, the apparent brightness,

https://github.comoahwaterfieldprice/python_primer/tree/master/ch_6 = Used this for help, but is too old for python3.7 3 Functions and branching the sun in light years, the apparentbrightness, and the luminosity. The apparent brightness is how bright the starslook in our sky compared to the brightness of Sirius A. Thehttps://github.comoahwaterfieldprice/python_primer/tree/master/ch_6 = Used this for help, but is too old for python 3.7

3 Functions and branching the sun in light years, the apparent brightness, and the luminosity. The apparent brightness is how bright the stars look in our sky compared to the brightness of Sirius A. The luminosity, or the true brightness, is how bright the stars would look if all were at the same distance compared to the Sun. The list data are found in the file stars.txt10, which looks as follows: 3.33 data 1.56) 0.45) 0.00006), ('Alpha Centauri A ('Alpha Centauri B, 4.3, 0.077, ('Alpha Centauri C', 4.2, 0.00001, ("Barnard's Star", ('Wolf 359' ('BD +36 degrees 2147', 8.2, 0.0003, 'Luyten 726-8 A, ('Luyten 726-8 B ('Sirius A' ('Sirius B ('Ross 154' ' 4.3, 0.26, 6.0, 0.00004, 0.0005), 7.7, 0.000001, 0.00002), 0.006) 8.4, 0.000003, 0.00006), 8.4, 0.000002, 0.00004), 8.6, 1.00, 8.6, 0.001, 9.4, 0.00002, 0.0005), 23.6), 0.003), The purpose of this exercise is to sort this list with respect to distance, apparent brightness, and luminosity. Write a program that initializes the data list as above and writes out three sorted tables: star name versus distance, star name versus apparent brightness, and star name versus luminosity. Hint. To sort a list data, one can call sorted(data), as in for item in sorted (data) However, in the present case cach element is a 4-tuple, and the default sorting of such 4-tuples results in a. list with the stars appearing in alphabetic order. This is not what you want. Instead, we need to sort with respect to the 2nd, 3rd, or 4th element of each 4-tuple. If such a tailored sort mechanism is necessary, we can provide our own sort function as a second argument to sorted: sorted(data, mysort). A sort function mysort must take two arguments, say a and b, and return -1 if a should become before b in the sorted sequence, 1 if b should become before a, and 0 if they are equal. In the present casc, a and b are 4-tuples, so we need to make the comparison between the right clements in a and b. For example, to sort with respect to luminosity we can write def mysort (a, b): if a[3] b [3]: return -1 elif a[3]b[3]: return 1 else: return 0 Filename: sorted-stars-data, py. http://tinyurl.com/puyasaa/funcif/stars.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!