Hello!
For two days now I can't figure out how to improve my solution to the problem so that the extra test would let me go further. I've read the page on common mistakes and still no progress. I've also seen some other solutions with code rather similar to mine (may be a little bit shorter).
Does the problem has something to do with multiple loops that I use or what else could it be? Is it global variables that brings trouble and if so how to fix them? Looking forward to your expertise.
All the best,
Carambagg
The code:
def house(plan):
new_plan = plan.splitlines()
new_plan.pop(0)
for i in new_plan:
if '#' not in i:
new_plan.remove(i)
else:
break
for i in new_plan[::-1]:
if '#' not in i:
new_plan.remove(i)
else:
break
width = 0
height = 0
for character in new_plan:
start_of_line = character.find('#')
end_of_line = character.rfind('#') + 1
current_width = end_of_line - start_of_line
height += 1
if current_width > width:
width = current_width
else:
continue
return width*height
Created at: 2022/07/07 10:58; Updated at: 2022/07/09 06:44
The question is resolved.