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 7789001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:09:27+00:00 2026-06-01T21:09:27+00:00

I am trying to create a triangle which takes in user inputted values and

  • 0

I am trying to create a triangle which takes in user inputted values and from the values would like to find the maximum route in these inputs. I intitally asked the question to find the maximum route in this: Finding the Maximum Route in a given input

Code:

def triangle(rows):
    for rownum in range (rows):
        PrintingList = list()
        print ("Row no. %i" % rownum)
        for iteration in range (rownum):
            newValue = input("Please enter the %d number:" %iteration)
            PrintingList.append(int(newValue))
            print()
def routes(rows,current_row=0,start=0):
    for i,num in enumerate(rows[current_row]):
        #gets the index and number of each number in the row
        if abs(i-start) > 1:   # Checks if it is within 1 number radius, if not it skips this one. Use if not (0 <= (i-start) < 2) to check in pyramid
            continue
        if current_row == len(rows) - 1: # We are iterating through the last row so simply yield the number as it has no children
            yield [num]
        else:
            for child in routes(rows,current_row+1,i): #This is not the last row so get all children of this number and yield them
                yield [num] + child


numOfTries = input("Please enter the number of tries:")
Tries = int(numOfTries)
for count in range(Tries):
    numstr= input("Please enter the height:")
    rows = int(numstr)
    triangle(rows)
    routes(triangle)
    max(routes(triangle),key=sum)

The error i get after inputting all my values for triangle:

Traceback (most recent call last):
  File "C:/Users/HP/Desktop/sa1.py", line 25, in <module>
    max(routes(triangle),key=sum)
  File "C:/Users/HP/Desktop/sa1.py", line 10, in routes
    for i,num in enumerate(rows[current_row]): #gets the index and number of each number in the row
TypeError: 'function' object is not subscriptable

Where is my error in my code? Need some help.. Thanks…

  • 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-06-01T21:09:29+00:00Added an answer on June 1, 2026 at 9:09 pm

    You are probably trying ot get the value of PrintingList, created inside the triangle function as the rowsvariable inside the routes function.

    For your program to work that way you have to add a return statement in your triangle function – that is, add a return PrintingList as the last statement there – and store this value when you call the function, and pass the stored value to the routes function – which means, the ending of your program should read something like:

    result = triangle(rows)
    routes(result)
    max(routes(triangle),key=sum)
    

    That will fix this problem, there may be other issues in the code above.

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

Sidebar

Related Questions

I am trying to create a triangle of numbers using Python from user input.
I am trying create a data.frame from which to create a graph. I have
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Trying to create a user account in a test. But getting a Object reference
Trying to create my first iPhone app that would play back audio. When I
I trying create a class derivated from System.Web.UI.Page and in override Render i set
I am trying create a small web application that allows a user to login
I am trying to create the polygons for a Doom 2 level from the
I am trying create a search box which will search datatables. The search box
I'm trying to create a pure CSS triangle for a tooltip. All browsers looks

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.