6) c. Maximum Line Length Examples




You are lost in a forest, but you know your actual and your home’s GPS location. You also know 2 earlier GPS locations where you’ve been today. You have to find your way home before sunset, otherwise, you will freeze and die.
Write a function with 8 input parameters (4 GPS locations with longitude and latitude) and calculate the time you need to get from your location to home touching the 2 known locations.

Given code:

1
2
3
4
5
6
7
8
import math

def time_to_home(my_x_location, my_y_location, frist_x_location, first_y_location, second_x_location, second_y_locaiton, home_x_location, home_y_locaiton):
    time = math.sqrt(abs(my_x_location - second_x_location) ** 2 + abs(my_y_location - second_y_locaiton) ** 2) + math.sqrt(abs(second_x_location - frist_x_location) ** 2 + abs(second_y_locaiton - first_y_location) ** 2) + math.sqrt(abs(frist_x_location - home_x_location) ** 2 + abs(first_y_location - home_y_locaiton) ** 2)
   
    return time

print("Time needed:", time_to_home(5,6,3,4,5,4,0,0))


After fixing as per PEP8 standards:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import math
def time_to_home(my_x_location, my_y_location, frist_x_location,
    first_y_location, second_x_location, second_y_locaiton, home_x_location,
    home_y_locaiton):
    time = math.sqrt(abs(my_x_location - second_x_location) ** 2 +\
        abs(my_y_location - second_y_locaiton) ** 2)
    time += math.sqrt(abs(second_x_location - frist_x_location) ** 2 +\
        abs(second_y_locaiton - first_y_location) ** 2)
    time += math.sqrt(abs(frist_x_location - home_x_location) ** 2 +\
        abs(first_y_location - home_y_locaiton) ** 2)
   
    return time

print("Time needed:", time_to_home(5,6,3,4,5,4,0,0))




At the zombie outbreak, it is important to know which city is safe and which is not. You will need to keep a list of safe cities because you have to find your new home.
Write a program that lists the safe cities, but doesn’t forget, that the zombies will sense if your code is ugly, so keep the length of your lines under 79 characters.

Given code:

1
cities = ["Edinburg", "New Orleans", "Venice", "Bangkok", "Miami", "Istanbul", "Budapest", "Berlin", "Wien"]


After fixing as per PEP8 standards:

1
2
cities = ["Edinburg", "New Orleans", "Venice", "Bangkok", "Miami",
        "Istanbul", "Budapest", "Berlin", "Wien"]




You are at your girlfriend’s house and you need to write her a love letter immediately otherwise she will rope you and put you in the basement. Because she is a geek you can impress her if you write a program.
Write a program that prints a love letter, but don’t forget that she is maximalist so keep the lengths of the line under the maximum value which is 79 characters.

Given code:

1
print("Oh my darling. I love you more than anybody else. I love you more, than a person can love anybody from this planet. I need you more, than a programmer a PC.")


After fixing as per PEP8 standards:

1
2
3
print("Oh my darling. I love you more than anybody else. I love you more,\
 than a person can love anybody from this planet. I need you more, than a \
programmer a PC."
)