473,396 Members | 1,838 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,396 software developers and data experts.

division bug?

a program:

a=10
b=5
print a/b

and its result: 0. If you run the program, you see always a sero (0),
but 10/5 is 2. Who can help me?
Jul 18 '05 #1
5 1316
"Milan" <mi******@yahoo.com> wrote in message
news:96************************@posting.google.com ...
a program:

a=10
b=5
print a/b

and its result: 0. If you run the program, you see always a sero (0),
but 10/5 is 2. Who can help me?


Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license()" for more information.
a = 10
b = 2
print a/b

5

What version are *you* running?
--
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.
Jul 18 '05 #2
On 2004-06-09, Milan <mi******@yahoo.com> wrote:
a program:

a=10
b=5
print a/b

and its result: 0. If you run the program, you see always a zero (0),
What answer do you want?
but 10/5 is 2. Who can help me?


Perhaps you can. :)
5/10 0 5.0/10.0 0.5 5//10 0 5.0//10.0

0.0

--
Grant Edwards grante Yow! Hold the MAYO & pass
at the COSMIC AWARENESS...
visi.com
Jul 18 '05 #3
mi******@yahoo.com (Milan) wrote in
news:96************************@posting.google.com :
a program:

a=10
b=5
print a/b

and its result: 0. If you run the program, you see always a sero (0),
but 10/5 is 2. Who can help me?


I don't know who can help you, but this is a Python newsgroup and if you
try your program in Python it prints 2, so perhaps you are using some other
language:
a=10
b=5
print a/b

2

If you are using Python, try cutting and pasting the exact code and the
problem you think you see, and we can try to help you from there.
Jul 18 '05 #4

Milan> a program:
Milan> a=10
Milan> b=5
Milan> print a/b

Milan> and its result: 0. If you run the program, you see always a sero
Milan> (0), but 10/5 is 2. Who can help me?

Works for me:

% python
Python 2.4a0 (#25, May 22 2004, 15:16:21)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
a=10
b=5
print a/b

2

I think you'll need to give more details (platform, version, actual
interpreter output, etc) to get any more useful help.

Skip

Jul 18 '05 #5
Milan wrote:
a program:

a=10
b=5
print a/b

and its result: 0. If you run the program, you see always a sero (0),
but 10/5 is 2. Who can help me?


You probably have reversed a & b in your program somewhere. Zero is the
correct result with the numbers reversed.
a = 10
b = 5
print "a/b = %s\nb/a = %s" % (a/b, b/a) a/b = 2
b/a = 0

If you import division from __future__ my guess is that you will see the
result of 0.5. If this is the case you have mixed a & b up somewhere.
from __future__ import division
print "a/b = %s\nb/a = %s" % (a/b, b/a)

a/b = 2.0
b/a = 0.5
--
Steven Rumbalski
news|at|rumbalski|dot|com
Jul 18 '05 #6

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

Similar topics

12
by: Tim Rowe | last post by:
If I do from __future__ import division then eval(1/2) gives me 0.5 as expected. But if I do print input("enter a sum: ") and enter 1/2 as the sum I get 0 as if I hadn't done the import. I thought...
2
by: Sebastian Haase | last post by:
Hi, I'm interested in having more people in our lab using numarray/NumPy instead of MatLab. For that I have put together a couple useful modules and written many myself. But then I got reminded of...
5
by: Jive | last post by:
I've got a program with Python 2.3 embedded. When I try to run a script containing "from __future__ import division", I get an exception: File "main2.py", line 3 from __future__ import divison...
19
by: Imbaud Pierre | last post by:
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more...
15
by: joel | last post by:
I have a table which I want to update by dividing one field into another. The update runs with no errors, but the results come out as only a positive integer number. The datatype for the result...
9
by: Marcin | last post by:
How I can make division of two numbers placed in arrays, example: short int a = {2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}; short int b =...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
2
by: kermit | last post by:
For a long time,, There has been a discussion of trueFor division versus integer division in Python. I myslef prefer that / be used for integer division since almost always, I want the...
13
by: jamesonang | last post by:
Supposed unsigned int(32 bits) is the largest number that computer can represent with a single variable. Now, i have a big integer ( less than 64 bit, but great than 32 bit) . i represent it by...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.