Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

hw5part1.1.PNG hw5part1.2.PNG hw5part1.3.PNG hw5part1.4.PNG hw5part1.5.PNG hw5part2.1.PNG hw5part2.2.PNG hw5part2.3.PNG hw5part3.1.PNG hw5part3.2.PNG hw5part3.3.PNG hw5part3.4.PNG hw5part3.5.PNG...

1 answer below »
hw5part1.1.PNG
hw5part1.2.PNG
hw5part1.3.PNG
hw5part1.4.PNG
hw5part1.5.PNG

hw5part2.1.PNG
hw5part2.2.PNG
hw5part2.3.PNG

hw5part3.1.PNG
hw5part3.2.PNG
hw5part3.3.PNG
hw5part3.4.PNG
hw5part3.5.PNG

hw5part4.1.PNG
hw5part4.2.PNG
hw5part4.3.PNG
hw5part4.4.PNG
Answered Same Day Oct 16, 2021

Solution

Prasun Kumar answered on Oct 17 2021
148 Votes
hw5_part2.py
"""
Author: Sancia Oommen
Date: October 16, 2020
"""
def pascal_level(a_list):
"""
:param a_list: a list represents the previous level in the pascal's triangle construction
:return: a new list with the previous elements summed
"""
# initializing variables
result = [1]
# generating pascal numbers
for j in range(1, len(a_list)):
result.append(a_list[j-1] + a_list[j])
result.append(1)
# returning results
return result
if __name__ == '__main__':
next_line = [1]
for i in range(10):
print(next_line)
next_line = pascal_level(next_line)
print(pascal_level([1, 2, 3, 4, 5]))
print(pascal_level([1, 1, 2, 3, 5, 8]))
print(pascal_level([1, 1, 2, 3, 5, 8, 13, 1]))
hw5_part3.py
"""
Author: Sancia Oommen
Date: October 16, 2020
"""
DOT = '.'
def print_robo_a
ay(room):
"""
ready made function to print the room
"""
for row in room:
for element in row:
if not element:
print(DOT.ljust(3), end=' ')
else:
print(str(element).ljust(3), end=' ')
print()
print()
def robo_vac(room, starting_y, starting_x):
"""
Computer a path through the room for the robot vacuum.
:param room: a 2d-grid representing the room,
'' blank strings are open spaces
:param starting_y: starting row (first index)
:param starting_x: starting column (second index)
:return: the updated room with the numbers.
"""
# initializing variables
nrows = len(room)
ncols = len(room[0])
moved = 1
serial = 1
cur_row = starting_y
cur_col = starting_x
# filling the starting location
if room[cur_row][cur_col] == '':
room[cur_row][cur_col] = serial
serial = serial+1
while moved:
# first try moving right
if cur_col+1 < ncols and room[cur_row][cur_col+1] == '':
cur_col = cur_col+1
room[cur_row][cur_col] = serial
serial = serial+1
# second try moving down
elif cur_row+1 < nrows and room[cur_row+1][cur_col] == '':
cur_row = cur_row+1
room[cur_row][cur_col] = serial
serial = serial+1
# third try moving left
elif cur_col-1 >= 0 and room[cur_row][cur_col-1] == '':
cur_col = cur_col-1
room[cur_row][cur_col] = serial
serial = serial+1
# fourth try moving up
elif cur_row-1 >= 0 and room[cur_row-1][cur_col] == '':
cur_row = cur_row-1
room[cur_row][cur_col] = serial
serial = serial+1
# if nothing works exit the loop
else:
moved = 0
# returning results
return room
if __name__ == '__main__':
my_room = [['' for _ in range(6)] for _ in range(6)]
print_robo_a
ay(robo_vac(my_room, 0, 0))
my_room_with_obstacles = [['' for _ in range(6)] for _ in range(6)]
for i in range(3, 5):
for j in range(3, 5):
my_room_with_obstacles[i][j] = 'x'
print_robo_a
ay(robo_vac(my_room_with_obstacles, 0, 0))
my_smaller_room = [['', '', ''], ['', 'x', 'x'], ['', '', 'x']]
print_robo_a
ay(robo_vac(my_smaller_room, 0, 0))
my_smaller_room = [['', '', ''], ['', 'x', 'x'], ['', '', 'x']]
print_robo_a
ay(robo_vac(my_smaller_room, 0, 2))
another_room = [
['', 'x', '', '', '', '', '', ''],
['', 'x', 'x', '', 'x', '', 'x', ''],
['', 'x', '', '', 'x', 'x', '', ''],
['', '', '', '', 'x', '', 'x', ''],
['', '', 'x', '', 'x', '', 'x', ''],
['', '', 'x', '', 'x', '', 'x', ''],
['', '', '', '', 'x', '', 'x', ''],
['', '', '', '', '', '', '', '']
]
print_robo_a
ay(robo_vac(another_room, 0, 0))
hw5_part4.py
"""
Author: Sancia Oommen
Date: October 16, 2020
"""
import json
def...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here