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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:39:42+00:00 2026-06-01T20:39:42+00:00

When i run the code below, the iteration starts from 0. I would like

  • 0

When i run the code below, the iteration starts from 0. I would like to change the row to start from row 1. How i do i change it? I tried typing rownum=1 before the iteration starts.

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)

Output :

Please enter the number of tries:2
Please enter the height:4
Row no. 0
Row no. 1
Please enter the 0 number:

Any help is appreciated.

  • 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-01T20:39:44+00:00Added an answer on June 1, 2026 at 8:39 pm

    Change:

    for rownum in range (rows):
    

    to:

    for rownum in range (1, rows+1):
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run the below code, everything goes great until I change the value
I am trying to run the code below but it keeps locking up my
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
the code below works fine but it takes an absolute age to run. How
Any ideas given the code below why the highlight is being triggered to run
When I run a Test Project on Visual Studio I use the code below
I'm trying to run the below-mentioned code in VB(Excel Macro) but I'm stuck with
When I run the following code, I get the exception below: ''# NOTE: ExcelApp
Ultimately I'm trying to transfer buffers from one machine to another. The code below
As far as I know, the code below gets a shape from the active

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.