On 12/22/2012 05:38 PM, Farrukh Ali wrote:
> Hi, i am using ActivePython 2.7.2.5, and windows 8 professional.
> well the original ex3.py is:
> print "I will now count my chickens:"
> print "Hens", 25 + 30 / 6
> print "Roosters", 100 - 25 * 3 % 4
> print "Now I will count the eggs:"
> print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 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
>
> And i have made ex3.py this way 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
>
>
> The author has given us extra credit to practice so here it is and the
> 5th point below, which i was asking.
>
> Extra Credit
> 1. Above each line, use the # to write a comment to yourself
> explaining what the line does.
> 2. Remember in Exercise 0 when you started python? Start python this
> way again and using the above characters
> and what you know, use python as a calculator.
> 3. Find something you need to calculate and write a new .py file that
> does it.
> 4. Notice the math seems "wrong"? There are no fractions, only whole
> numbers. Find out why by researching
> what a "floating point" number is.
> 5. Rewrite ex3.py to use floating point numbers so it's more accurate
> (hint: 20.0 is floating point).

OK, so his point #4 is that for eggs, 1/4 gives a zero, not a 0.25.  So
you lose accuracy in that sense.  So point #5 is to allow fractions to
propagate.

Note that in Python 3.x,  1/4 will already give a float, rather than an
int, and if you want the 2.x behavior, you would write it as 1//4

Otherwise, it looks right to me.

-- 

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to