473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Creating number format

440 256MB
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 2907
bvdet
2,851 Expert Mod 2GB
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 256MB
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,Ymin = 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 256MB
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%0Indexd%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 Expert Mod 2GB
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%0Indexd%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 256MB
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 Expert Mod 2GB
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
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",...
3
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...
1
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...
2
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...
12
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...
7
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...
4
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...
1
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...
7
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. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.