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

  • SEARCH
  • Home
  • 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 8621357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:48:09+00:00 2026-06-12T06:48:09+00:00

First, yes I know that str(n).zfill(width) works very well at padding zeros in front

  • 0

First, yes I know that str(n).zfill(width) works very well at padding zeros in front of digits.

But has anybody tried writing their own algorithm for this? I tried…

def printNodeNames(name, first, last, numPadZeros):
    for i in range(first, last+1):
        s = ""
        for j in range(0, numPadZeros):
            if i >= 10**j and i < 10**(j+1):
                zeros = ""
                for k in range(0, numPadZeros-j):
                    zeros = zeros + "0"
                s = name + zeros + str(i)
        nodes[i-1:i] = [s]
    return nodes

The above function is suppost to print node names of a compute cluster, BUT IT DOES NOT WORK. Example:

>>> printNodeNames('node', 1, 12, 1)
['node01', 'node02', 'node03', 'node04', 'node05', 
 'node06', 'node07', 'node08', 'node09', '', '', '']

As just an excercise, can anybody figure out why it doesn’t work?

  • 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-12T06:48:10+00:00Added an answer on June 12, 2026 at 6:48 am

    You are only assigning a value to s if your if statement is true. In the case of node 10 and above, the if statement is never true so s remains "".

    To change it move the assignment of s out of the inner for block. and set zeros = "" before the for block.

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

Sidebar

Related Questions

Yes, I know that less was in first place written for node.js. But I
I know that __builtin__ sorted() function works on any iterable. But can someone explain
FIRST: Yes, I know about CONCATENATE and CONTINUEIF, but I might not be smart
First off, yes, I know that the VS Setup Projects are evil. It's what
First, yes, I know that regex should never be used to parse HTML, however,
I have an AXIS2/JAX-WS web service using a code first implementation (yes I know,
First off: I know that this isn't reliable for actually checking if I can
Iam still getting the exception lazyinitializationexception. Yes, i know that it means, that the
I know that there are a lot of questions about this topic, but unfortunately
I'm trying to connect to a web service using IO::Socket::INET (yes, I know that

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.