Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Above is the data txt file. Modify your function from the following python code to take only the filename as an argument. It should return

image text in transcribed

Above is the data txt file.

Modify your function from the following python code to take only the filename as an argument. It should return a dictionary, D, that encodes all of the data so you can do e.g.: D['MARS']['Ring System?'] and output No. Print the entire output of D['MARS'] (with a clean format) as a check.

# function to retrieve the planet data def planet_data(filename,col_id,row_id):

# chaning the row id, col id to lower case row_id=row_id.lower() col_id=col_id.lower()

# opening the file f=open('planetary-fact-sheet.txt','r') cols={} count=0 # empty list t=[]

# looping through every line for number,line in enumerate(f): # removing the space at the end line=line.strip() # skipping first two lines if number ==0 or number ==1: continue # getting the planet names for column ids if number==2: planets=line.split('\t') for p in planets: p=p.strip() if p not in cols: count+=1 cols[p]=count else:

# getting the planet data r=[] data=line.split('\t') for c in data: r.append(c) t.append(r) flag=0

# checking for column id planet_name='' planet_index='' for key in cols.keys(): if col_id in key.lower(): planet_name=key planet_index=cols[key] flag=1 i=-1 data_name='' for index,item in enumerate(t): for data in item: data=data.lower() if row_id in data: data_name=data i=index break if i==-1 and flag ==0: print('Row id and column are not valid') return elif i==-1: print('Row id is not valid') elif flag==0: print('Col id is not valid') else: print( '%s : %s = %s ' %(planet_name.capitalize(),data_name.capitalize(),str(t[i][planet_index])))

Some information about the planets in our solar system # Adapted from http:/ssdc.gsfc.nasa.gov/planetary/factsheet/ MERCURY URANUS VENUS EARTH MOON PLUTO MARS JUPITER SATURN NEPTUNE 86.8 102 Mass (10~24kg) 0.330 4.875.97 .073 0.642 1898 568 0.0146 Diameter (km 4879 12,104 12,756 3475 6792 142,984 120,536 51,118 49,528 2370 Density (kg/m 3) 1638 Gravity (m/s 2) 37 5427 5243 5514 3340 3933 1326 687 1271 2095 8.7 35.521.3 10.7 -17.2 10.7 17.2 3.7 23.1 9.0 11.0 Escape Velocity (km/s) 4.3 23.5 Rotation Period (hours) 1407.6 -5832.5 23.9 655.7 24.6 9.9 16.1 Length of Day (hours) 4222.6 2802.0 24.0 708.7 24.79.9 16.1 Distance from Sun (1046 km) 2872.5 4495.1 5906.4 Perihelion (10 6 km) 46.0 107.5 147.1 0.363* 206.6 740.5 1352.6 2741.3 4444.5 4436.8 Aphelion (10 6 km) 4545.7 7375.9 Orbital Period (days) 88. 224.7 365.2 27.3 687. 4331 10,747 30,589 59,800 90,560 Orbital Velocity (km/s) 47.435. 29.8 1.0 5.4 Orbital Inclination (degrees) 7.0 0.8 10.4 11.2 2.4 59.5 1.3 -153.3 153.3 57.9 108.2 149.6 0.384* 227.9 778.6 1433.5 69.8 108.9 152.1 0.406* 249.2 816.6 1514.5 3003.6 24.1 13.1 9.7 6.8 4.7 0.0 5.1 1.9 1.3 2.5 1.8 17.2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is job rotation ?

Answered: 1 week ago