Beginner: Trying to get REAL NUMBERS from %d command

Joel Goldstick joel.goldstick at gmail.com
Sun Dec 30 23:54:30 CET 2012


On Sun, Dec 30, 2012 at 5:37 PM, Alvaro Lacerda <alacerda617 at gmail.com>wrote:

> The code I wrote is supposed to ask the user to enter a number;
> Then tell the user what's going to happen to that number (x / 2 + 5) ;
> Then give the user an answer;
>

Try x / 2.5 + 5

>
> I succeeded getting results from even numbers, but when I try diving an
> uneven number (i.e. 5) by 2, I get only the whole number (i.e. 2)
>
> I'm trying to get full number result using the %d command, I've tried to
> add the line "from __future__ import division" to the beginning of my code,
> but I haven't been succeeded.
>
> I also tried making my numbers decimals (i.e. 2.0 instead of just 2)
>
>
> Below is my program and thanks for the help :)
>
>
>
> from __future__ import division;
>
> def decimal_percent_test():
>     number = input("Enter a number: ");
>     print number, "will be divided by 2 then added by 5!";
>     print " %d divided by %d is %d plus %d is... %d !"
> %(number,2,number/2,5,number/2+5);
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121230/100bbd80/attachment.html>


More information about the Python-list mailing list