473,569 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datatype of non-negative values

Hi,

Is there a datatype in python which allows no negative values? I
subtract several times something from a value and I don't want to chek
everytime if this value is still bigger or equal 0.

Thanks for help!
Dirk Hagemann
Jul 18 '05 #1
2 1921
What exactly do you want to happen when result
would be negative? I'll guess be zero:

pseudocode:

x=value
x=max(x-something, 0)

That way if it goes negative, it sticks to zero.

Larry Bates
Dirk Hagemann wrote:
Hi,

Is there a datatype in python which allows no negative values? I
subtract several times something from a value and I don't want to chek
everytime if this value is still bigger or equal 0.

Thanks for help!
Dirk Hagemann

Jul 18 '05 #2
A result smaller than 0 should be just invalid.

I'd like to work with "try" and "except" like this:
value=20
try:
value=value-23
except:
print 'value is smaller than 23'

Now it should run into the "except".

Dirk Hagemann
Larry Bates <lb****@syscono nline.com> wrote in message news:<0q******* *************@c omcast.com>...
What exactly do you want to happen when result
would be negative? I'll guess be zero:

pseudocode:

x=value
x=max(x-something, 0)

That way if it goes negative, it sticks to zero.

Larry Bates
Dirk Hagemann wrote:
Hi,

Is there a datatype in python which allows no negative values? I
subtract several times something from a value and I don't want to chek
everytime if this value is still bigger or equal 0.

Thanks for help!
Dirk Hagemann

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
13421
by: Sanjay Minni | last post by:
What is the datatype to be used for Primary Key columns for most optimised access given that - There will be a single column primary key only - The values will only be integers (but as strings) at least 12 digits (characters) long - all positions will be occupied (no leading 0's) - Tables may have upto 1m+ rows
5
9900
by: Amit | last post by:
I am facing a problem while using SQL Server with VB application. Implicit conversion from datatype text to nvarchar is not allowed. Use the convert function to run this query. When i see the trace file, i see one stored procedure called but no lines of code get executed, and immediately after that the ROLLBACK TRANSACTION occurs and the...
8
1939
by: Eternally | last post by:
Hi folks, I've got a program which has a function which uses templates to accept parameters of any type. Works well, but there's one certain datatype which I want to special case and do an extra thing to. The datatype is a class I made. Is there anyway for me to test a parameters datatype in a template using function?
0
1674
by: SoYouKnowBrig | last post by:
Hi All, I am using Microsoft.ApplicationBlocks.Cache.CacheManager to persist a System.Data.Dataset object. This Dataset object has a DataTable that is created from an existing DataTable using the Clone() method. Before I add the new DataTable to the DataSet, I change the DataType of a DataColumn from System.String to System.Int64. I then...
9
1734
by: sandorf | last post by:
When I write: int a; and I want another name for "int", I can simply write typedef int interger but what if I want a more descriptive name for the datatype int a; ? typedef int two_intergers of course won't work. Thanks.
14
3000
by: Elias Farah | last post by:
Hi All, What are people's experience in timing Query Performance? I have tried in vain, but get many unpredictable results, with execution proceeding in the background and problems of timing precision. I am trying to assess my applications performance difference using FK using BYTE instead of LONG type. and not enforcing integrity at the...
4
1163
by: romy | last post by:
Hi I'm about to write a DLL that has to recieve and XML document as one of its parameters. However , I'm not sure that the consumers of this DLL will work under the ..NET framework, (such as access or vb6) hence they do not support class XMLDocument. What are my options ?
3
3335
by: Sri | last post by:
In VB, to know the field type of a column stored in a recordset the command I use is If rsQuery.Fields(k).Type = adCurrency Then How will I achieve the same in ASP.net. I could not find a currency data type in asp.net and the type is idenfied as decimal. I have two fields defined in Sql-Server, one is money and other is decimal. In...
4
11955
by: Orchid | last post by:
How can I change a Date datatype to a Number datatype? For example, I want a date 10/31/2006 to show 1031 as Number datatype. But I don't want it becomes 39021. What formula should I use? Thanks for your help!!
11
1875
by: BD | last post by:
Hi, all. I'm running 8.2 on Windows. This is a development platform for a project whose production environment is running on a mainframe. I believe that the RI compilation process is not quite as robust on Windows as it is in other environments. Here's what I'm finding:
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
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...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.