1 Input Parameter: a tweet line Return: the latitude value as a float. Hint: You
ID: 3829887 • Letter: 1
Question
1 Input Parameter: a tweet line
Return: the latitude value as a float.
Hint: You will need combinations of splitting and slicing to make this work.
Steps:
Convert a string like: "[25.8, -80.2] 5 2011-09-03 05:40:14 pizza rustica #ftw" into "[25.8, -80.2]"
Convert a string like: "[25.8, -80.2]" into "[25.8"
Convert a string like: "[25.8" into "25.8"
Convert a string like: "25.8" into a float and return.
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
get_latitude("[41.37, -81.46] 6 2011-08-28 19:02:28 yay. little league world series!") 41.37
get_latitude("[25.8, -80.2] 5 2011-09-03 05:40:14 pizza rustica #ftw") 25.8
Explanation / Answer
def get_latitude(line):
lat = line.split(",")[0]
lat = lat[1:]
return float(lat)
print(get_latitude("[41.37, -81.46] 6 2011-08-28 19:02:28 yay. little league world series!"))
print(get_latitude("[25.8, -80.2] 5 2011-09-03 05:40:14 pizza rustica #ftw"))
# code link: https://paste.ee/p/PIptq
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.