id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

gaurav1780@gmail.com 04_lists > distance_from_home
prev  |  next  |  chance

In a legacy system, directions are stored by magnitude followed by direction. Thus, "12E" represents " travel 12 kms towards east, "4N" represents 4kms to the north, "120S" represents 120 kms south and finally "3W" represents 3 kms towards west. Given a list that holds a collection of individual directions, return how far from the starting point will we be. You can use int(string) to convert a string to an integer, provided it can be converted. You will also need String functions such as string[index] and string[start:end]. distanceFromHome(["10N", "10W", "10S", "10E"]) → 0.0 distanceFromHome(["10N", "10W", "10S", "8E"]) → 2.0 distanceFromHome(["8N", "6W"]) → 10.0


distance_from_home(['10N', '10W', '10S', '10E']) → 0.0
distance_from_home(['10N', '10W', '10S', '8E']) → 2.0
distance_from_home(['8N', '6W']) → 10.0

...Save, Compile, Run (ctrl-enter)

def distance_from_home(directions):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 4 Post-solution available

Copyright Nick Parlante 2017 - privacy