Beginner: Trying to get REAL NUMBERS from %d command

Alvaro Lacerda alacerda617 at gmail.com
Sun Dec 30 23:37:53 CET 2012


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;

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);

                
                   
    



More information about the Python-list mailing list