Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 Input Parameter: a star\'s name Return: the star string of the star with match

ID: 3829927 • Letter: 1

Question

1 Input Parameter: a star's name

Return: the star string of the star with matching name in the file stars.txt.
If no star with a matching name can be found, an error message should be printed and the empty string ("") should be returned.

Hint: Search the file line by line using the get_star_name() function to see if the correct star string has been found.

Below are example function calls.

get_star_string("POLARIS") "0.010128,0.007897,0.999918,8890,1.97,424,POLARIS"

get_star_string("BOB") "" with printed error msg: "ERROR: No star called BOB could be found."

Explanation / Answer

def get_star_string(s):
with open("stars.txt", "r"):
for line in fh:
if s in line:
return line
print("Didn't found " + s + " in file stars.txt")
return ""

# code link: https://paste.ee/p/EIDzX