Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:56:24+00:00 2026-05-23T08:56:24+00:00

Here’s the code, part of a solution to problem 11 in Euler Project :

  • 0

Here’s the code, part of a solution to problem 11 in Euler Project:

sum_d = 0
j = 0
while j < 20:
    i = 0
    while i < 20:
        try:
            sum_d = grid[j][i] * grid[j+1][i+1] * grid[j+2][i+2] * grid[j+3][i+3]
            if sum_d > result:
                result = sum_d
        except IndexError:
            pass
        i += 1
    j += 1

My question is whether catching those exceptions is considered a code smell? I can see that it will be tougher to debug such code (say, I accidentally looped over 19 items instead of 20, it will be harder to trace) but it is much more elegant then, say, coding i < (GRID_WIDTH - NUM_ITEMS_IN_PRODUCT)
in the loop check.

P.S. I already solved the problem, I’m talking about the style of code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:56:25+00:00Added an answer on May 23, 2026 at 8:56 am

    Spoiler: Here’s part of my solution for problem 11.

    for x in range(0,16):
        for y in range(0,16):
            prod = p[y][x] * p[y+1][x+1] * p[y+2][x+2] * p[y+3][x+3]
            m = max(m, prod)
    

    Using exceptions instead of basic control structures is imho always a bad idea. This time you can get away with looping through the numbers 0..15!

    Also, if you muliply stuff you get a product, not a sum. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my situation. My solution structure is as follows. Project Used to handle
here are 2 screen shots when i try to debug my code in visual
Here a simple question : What do you think of code which use try
Here's a problem I ran into recently. I have attributes strings of the form
Here is my code, which takes two version identifiers in the form 1, 5,
Here's a coding problem for those that like this kind of thing. Let's see
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here is my current problem. I am working with the chat module and I'm
Here’s a problem I’ve really been struggling with. I need to merge two sorted
here a a piece of code that is supposed to loop over and over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.