Can someone please help me with this because it is driving me crazy.
I wrote a program which prompts the user to enter a number
I convert the string to an integer
when i print the value it sometimes comes out as a decimal e.g. 3.0
I thought an integer was a whole number so how is it printing as a decimal?
bryann
0
Newbie Poster
Recommended Answers
Jump to PostNeed to see your code.
Jump to Post3/2 will be 1.5
3//2 will be 1
Jump to PostUse the floor divider // instead. The typing system of Python will change your int to a double, if the / operator does not divide exactly. Only Vegaseat can tell if what I say here is wrong!
Jump to PostThe Problem with Integer Division
Not much else to say if you read that post.
One tips is to usefrom __future__ import division
for Python 2.x.
Python 3.x has made chage …
All 15 Replies
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
bryann
0
Newbie Poster
bryann
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
bryann
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
bryann
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
bryann
0
Newbie Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
snippsat
661
Master Poster
Gribouillis
commented:
good link
+14
dashing.adamhughes
0
Light Poster
sneekula
969
Nearly a Posting Maven
iJimJones
15
Newbie Poster
bryann
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.