6) b. Indentation Examples




At the agency, you must track every suspicious person. To keep your country safe and your allies alive you must know which enemy agent where is at the moment. You need to send a message if an agent is in danger, but the agency can send only one data per message. You have to find a solution to minimize the number of messages sent to an agent.
Write a program that returns an agent’s first and last name, age, actual city and danger level in one string.
Don’t forget that the agency has a strict policy, where you can use only 79 characters in a row.

Given code:

1
2
3
4
5
6
def concatenate_date(agent_first_name, agent_last_name, agent_age, agent_actual_city, agent_danger_level):
    data = agent_first_name + " " + agent_last_name + " " + agent_age + " " + agent_actual_city + " " + agent_danger_level

    return data

print(concatenate_date("John", "Whick", 30, "London", 10))


After fixing as per PEP8 standards:

1
2
3
4
5
6
7
8
def concatenate_date(agent_first_name, agent_last_name, agent_age,
                    agent_actual_city, agent_danger_level):
    data = agent_first_name + " " + agent_last_name + " " + agent_age
    data += " " + agent_actual_city + " " + agent_danger_level

    return data

print(concatenate_date("John", "Whick", 30, "London", 10))




At the Coronavirus outbreak, some people from your city just got infected. You need to know which zones of your city are not safe anymore, so you will need to create a database with the infected zones.
Write a program where you give at least 6 streets from your city which is infected. Don’t forget, that the coronavirus infects easily if you are not respecting the coding standards. Keep your lines under 79 characters. Also, be careful. The last two people who broke the coding standards did not survive.

Given code:

1
2
3
infected_streets = ["Charles de Gaulle street", "Witold Rowicki street", "Credit Street", "Holy Cross Street", "Low street", "Wiktor Gomulicki street"]

print(infected_streets)


After fixing as per PEP8 standards:

1
2
3
4
5
6
7
8
9
infected_streets = [
        "Charles de Gaulle street",
        "Witold Rowicki street",
        "Credit Street",
        "Holy Cross Street",
        "Low street",
        "Wiktor Gomulicki street"
    ]
print(infected_streets)




You are in a maze, that changes the routes every hour. You need to find your way out before sunset unless
you will be eaten by terrible monsters. In the middle of the maze, you see a screen. On the screen, you see only one file with the map for the next hour, but you can open this file only with a program written by you.
Write a program that prints the map to the screen to find your way out. In the file, you will see ones in place of
a wall and zeros instead of the route.

Given code:

1
2
3
4
5
6
7
def generate_maze():
    maze =[[1, 1, 0, 1, 1, 1, 1],[1, 0, 0, 0, 1, 0, 1],[1, 0, 1, 0, 1, 0, 1],[1, 1, 1, 0, 1, 0, 1],[1, 0, 1, 0, 0, 0, 1],[1, 0, 0, 0, 1, 0, 1],[1, 1, 1, 1, 1, 1, 1],]
   
    return maze

maze = generate_maze()
for row in range(len(maze)): print(str(maze[row]) + " ")


After fixing as per PEP8 standards:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def generate_maze():
    maze =[
        [1, 1, 0, 1, 1, 1, 1],
        [1, 0, 0, 0, 1, 0, 1],
        [1, 0, 1, 0, 1, 0, 1],
        [1, 1, 1, 0, 1, 0, 1],
        [1, 0, 1, 0, 0, 0, 1],
        [1, 0, 0, 0, 1, 0, 1],
        [1, 1, 1, 1, 1, 1, 1],
    ]
   
    return maze

maze = generate_maze()
for row in range(len(maze)):
    print(str(maze[row]) + " ")