[Tutor] check it for me

Dave Angel d at davea.name
Sat Dec 22 22:54:53 CET 2012


On 12/22/2012 04:02 PM, Farrukh Ali wrote:
> Hi Tutor,
>
> I am new to python, and a novice in the world of programming, I am learning python from learnpythonthehardway, and now a little bit confused in exercise 3, where the author of the book wants us to rewrite the ex3.py by saying 
> Rewrite ex3.py to use floating point numbers so it’s more accurate (hint: 20.0 is floating point).
>
> so I have written the source code in this manner using floating points, here it is:
>
Welcome to the forum. I hope you enjoy learning Python, and we'll try to
help as much as we can.

Please send your mail as plain text. Your html mail was triple spaced,
and very hard to make sense of. I've removed the extra spaces below.

>  
>
> print "I will now count my chickens:"
> print "Hens",25+30.0/6
> print "Roosters",100 - 25.0 * 3.0 % 4
> print "Now I will count the eggs:"
> print 3+2+1-5.0+4.0%2-1/4.0+6
> print "Is it true that 3+2<5-7?"
> print 3+2<5-7
> print "What is 3+2?",3+2
> print "What is 5-7?",5-7
> print "Oh, that's why it's False."
> print "How about some more."
> print "Is it greater?", 5>-2
> print "Is it greater or equal?", 5>=-2
> print "Is it less or equal?", 5<=-2
> print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6
>  
>
> kindly check that whether I have done right?

To be honest, I don't understand what the author meant by

"to use floating point numbers so it’s more accurate"

For whole numbers, ints are always at least as accurate as floats.  Once you start dividing those ints, you'll probably need floats or some other equivalent non-integer.  So you have a formula for eggs which gives a non-integer;  I'm not sure what sense that makes.

Perhaps if you also showed us the original ex3.py, it'd make more sense.  Or maybe somebody else reading your message has downloaded the course.

It is also usually useful to state what Python version you're using
(presumably 2.7) and what version of Windows.For example, the divide
operator is defined differently in python 3.x





-- 

DaveA



More information about the Tutor mailing list