1 Input Parameter: a tweet line Return: the longitude value as a float. Hint: Yo
ID: 3829921 • Letter: 1
Question
1 Input Parameter: a tweet line
Return: the longitude value as a float.
Hint: You will need combinations of splitting and slicing to make this work.
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_longitude("[41.37, -81.46] 6 2011-08-28 19:02:28 yay. little league world series!") -81.46
get_longitude("[25.8, -80.2] 5 2011-09-03 05:40:14 pizza rustica #ftw") -80.2
Explanation / Answer
def get_longitude(s):
s = s.split(", ")[1]
s = s.split("]")[0]
return float(s)
print(get_longitude("[41.37, -81.46] 6 2011-08-28 19:02:28 yay. little league world series!"))
print(get_longitude("[25.8, -80.2] 5 2011-09-03 05:40:14 pizza rustica #ftw"))
# code link: https://paste.ee/p/MMKep
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.