473,857 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating number format

440 Contributor
I have a input format XX:YY:ZZ and the start value may be 'n' digit numbers for X,Y,Z.

So I have to assign the numbers based on the above format ( Format may change)

Say

Example - 1

Inputs :

Number Format :- XX:YY:ZZ

Start Values for
X = 1
Y = 5
z = 1

I have to create 5 numbers with +1 increment for 'Y'direction value

Here 'Z' will be constant

XX:YY:ZZ

010501
010601
010701
010801
010901
011001


Example - 2
------------------
Number Format :- X:YY:Z
X = 1
Y = 5
z = 1

I have to create the numbers with +1 increment for 'X' & 'Y'direction value

Here 'Z' will be constant
X:YY:Z

010501
010601
010701
010801
010901
011001
020501
020601
020701
020801
020901
021001

How to arrive at these numbers based on the format and the start numbers?

Thanks
PSB
Apr 24 '07 #1
6 2922
bvdet
2,851 Recognized Expert Moderator Specialist
I have a input format XX:YY:ZZ and the start value may be 'n' digit numbers for X,Y,Z.

So I have to assign the numbers based on the above format ( Format may change)

Say

Example - 1

Inputs :

Number Format :- XX:YY:ZZ

Start Values for
X = 1
Y = 5
z = 1

I have to create 5 numbers with +1 increment for 'Y'direction value

Here 'Z' will be constant

XX:YY:ZZ

010501
010601
010701
010801
010901
011001


Example - 2
------------------
Number Format :- X:YY:Z
X = 1
Y = 5
z = 1

I have to create the numbers with +1 increment for 'X' & 'Y'direction value

Here 'Z' will be constant
X:YY:Z

010501
010601
010701
010801
010901
011001
020501
020601
020701
020801
020901
021001

How to arrive at these numbers based on the format and the start numbers?

Thanks
PSB
This is not ideal, but it seems to meet your requirements:
Expand|Select|Wrap|Line Numbers
  1. def format_numbers(X,Y,Z,n,u):
  2.     x,y,z = X,Y,Z
  3.     outList = []
  4.     while x <= u:
  5.         while y <= u:
  6.             if n == 0:
  7.                 return outList
  8.             else:
  9.                 outList.append('%02d%02d%02d' % (x, y, z))
  10.                 y += 1
  11.                 n -= 1
  12.         y = Y            
  13.         x += 1
  14.     return outList
  15.  
  16. print format_numbers(1,5,1,8,10)
  17.  
  18. >>> ['010501', '010601', '010701', '010801', '010901', '011001', '020501', '020601']
Apr 24 '07 #2
psbasha
440 Contributor
Thanks for the reply.
But the number format will be changing

Say:

a) Format :- X:Y:Z

Then the values will be 111 to 991 ( Z = 1 Constant,Xmin,Y min = 1 and Xmax,Ymax = 9)

b) Format :- XX:YY:ZZ

Then the values will be

010101 to 999901 ( Z = 01 Constant, Xmin,Ymin = 01 and Xmax,Ymax = 99)

c) Format :- XX:Y:ZZ
Then the values will be

01101 to 99901 ( Z = 01 Constant, Xmin =01,Ymin = 1 and Xmax =99,Ymax = 9)

d) Format :- XX:Y:ZZ
Then the values will be

01101 to 99199 ( Y = 1 Constant, Xmin =01,Zmin =0 1 and Xmax =99,Zmax = 99)

and soon.

Is it possible to create the above formating in amore generic way.

Input will be format and the start index of X,Y,Z (But one index will be constant,out of three)

-PSB

-PSB
Apr 24 '07 #3
psbasha
440 Contributor
Instead of giving constant value (say 4 in this case),is it possible to give variable name as shown below and get the solution

[code]
Existing:
>>> outList =[]
>>> outList.append( '%04d%04d%04d' % (100, 51, 1))
>>> [ '010000510001']

Required:
Index will be varying based on the format

>>> Index = 2
>>> outList =[]
>>> outList.append( '%0Indexd%0Inde xd%0Indexd' % (100, 51, 1))
>>> outList
['100d51d1d']

But I am getting the expected output.May be my syntax is wrong.Correct me for the format

-PSB
Apr 24 '07 #4
bvdet
2,851 Recognized Expert Moderator Specialist
Instead of giving constant value (say 4 in this case),is it possible to give variable name as shown below and get the solution

Existing:
>>> outList =[]
>>> outList.append( '%04d%04d%04d' % (100, 51, 1))
>>> [ '010000510001']

Required:
Index will be varying based on the format

>>> Index = 2
>>> outList =[]
>>> outList.append( '%0Indexd%0Inde xd%0Indexd' % (100, 51, 1))
>>> outList
['100d51d1d']

But I am getting the expected output.May be my syntax is wrong.Correct me for the format

-PSB
You could do something like this:
Expand|Select|Wrap|Line Numbers
  1. >>> def plcs(n,p):
  2. ...     n = str(n)
  3. ...     return (p-len(n))*'0'+n
  4. ... 
  5. >>> '%s%s%s' % (plcs(5,4), plcs(6,4), plcs(8,4))
  6. '000500060008'
  7. >>> 
Apr 24 '07 #5
psbasha
440 Contributor
You could do something like this:
Expand|Select|Wrap|Line Numbers
  1. >>> def plcs(n,p):
  2. ...     n = str(n)
  3. ...     return (p-len(n))*'0'+n
  4. ... 
  5. >>> '%s%s%s' % (plcs(5,4), plcs(6,4), plcs(8,4))
  6. '000500060008'
  7. >>> 
Thanks BV,

It washelpful
Apr 24 '07 #6
bvdet
2,851 Recognized Expert Moderator Specialist
Thanks BV,

It washelpful
You are welcome. A generic function to generate number sequence strings is a bit more work than I have time for at the moment.
Apr 24 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1489
by: shank | last post by:
I'm creating a spreadsheet online via ASP. I have the following at the page top... <% Response.contenttype = "application/vnd.ms-excel" %> <% Response.AddHeader "Content-Disposition", "filename=FullList.xls" %> It works fine for some 60+ manufacturer listings. However, it balks on one single manufacturer. By chance, this manuf has 18,000+ records. The others, less than 10,000. Is there a limit to the number of records I can convert to...
3
4616
by: Matt Smolic | last post by:
Does anyone know where I can get some info on creating customer account numbers, part numbers and such. In other words what the logic is behind their creation. I am not looking for code, just how they go about it. I don't want to use something like a phone number or anything else that may change over time. Any info would be greatly appreciated. Thanks Matt
1
3412
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set the Required, Allow Zero Length and Indexed attributes. I have tried but keep getting a syntax error. Also, can I set the default value of a field in code? Has anyone some examples of these. TIA
2
6250
by: Todd_M | last post by:
I was wondering what anyone might suggest as "best practice" patterns for streaming out fixed formatted text files with C#? Let's say we get our data in a dataset table and we need to iterate over thousands..potentially tens of thousands of rows to create a properly formatted text file -- like an ACH file, for example. In there you typically have a header, a body block of detail rows and a trailer. (The trailers usually contain sums of the...
12
3186
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without restarting the application. What I did was to create an AppDomain that loaded the plugins and everything was great, until I tried to pass something else that strings between the domains...
7
7685
by: nono909 | last post by:
I wrote the following time class for the following assignment.i need help in completing this program pleasee. Write a class to hold time. Time is the hour, minute and seconds. Write a constructor that will allow the user of your class to initialize a time or set the time to all zeros if not initialized. Include all the operators listed above. Your program will need to read from a file of times and commands. There will be a number at the top...
4
2249
by: mtgrizzly52 | last post by:
Good evening all. I have a challenge that I have no clue on how to accomplish it. I am so close to completing a challenging database it's scary, but through beta testing we discovered a need for method of generating a series of numbers and letters that can't be duplicated, well at least not easily that is. That is why I thought a button that generates what we need through a randomizer function. Ok, heres the skinny on what needs to be...
1
1639
by: lilsugaman | last post by:
Hi I have created an Inventory program that displays the product name, item number, how many units, and it's price and at the end displays the totals, I have to modify the program so that it will handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the...
7
13699
by: Andrus | last post by:
How to create format string for decimal data type which shows blank for zero and default format otherwize ? I tried format string "f;f;#" but this shows f for nonzero numbers. Andrus. using System.Windows.Forms;
0
9923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10807
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7939
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5967
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4190
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.