[Tutor] Starting over with Python
R. Alan Monroe
amonroe at columbus.rr.com
Thu Dec 14 02:44:31 CET 2006
> odd =1
>>>>while odd <=100:
> if (odd%2)==1:
> print odd
> odd = odd + 1
> -------------------------------------------------------------------------------------------------
> I get a list of the odd numbers from 1 to 99. But now if I wanted to add
> those number together (i.e. 1 + 3 +5 + 7 etc.), what line of coding should I
> include?
Hint: create an additional variable called oddsum to tally it up. Add
each number to that. There are several approaches but this fits into
your existing program the easiest, I think.
Alan
More information about the Tutor
mailing list