LiveWire Peer Support Network

Printable Version of Topic "Problem with code"

- LiveWire Teen Forums & College Forums (http://www.golivewire.com)
-- (http://www.golivewire.com/forums/support-technical.html)
--- Computer Virus & Anti-Virus Software (http://www.golivewire.com/forums/forum-209-s-0.html)
---- Problem with code (http://www.golivewire.com/forums/peer-yyisipt-support-a.html)


-- Posted by tiara at 5:19 am on Nov. 14, 2008

Q3: Write a program using a while loop that will add both all the odd and all the even
numbers from 1 to 10 inclusive i.e. 1+3+5+7+9 and 2 + 4 +6 +... . The results are then
printed out.


num=input ("enter value")

while num<10:
         num=num+2
         print num,
print "goodbye"

The results are there and so is the problem:
enter value:1
3 5 7 9 11 goodbye

It goes up to 11....how do I change it??

And should it be a variable or not??


-- Posted by bigdutchman at 5:20 am on Nov. 14, 2008

change it to while num is less than 8, not 10.

now it's still adding 2 and printing if it's 9, printing 11.


-- Posted by allsmiles at 5:32 am on Nov. 14, 2008

<9, not <10.


-- Posted by Tubbz at 5:36 am on Nov. 14, 2008

for less than 10, it gives n=9 and n+2 (11)


-- Posted by Wii Tard at 5:38 am on Nov. 14, 2008

this reminds me of VB....i hate it


-- Posted by matto at 5:54 am on Nov. 14, 2008

if you do your calculation or output or whatever before incrementing, the problem will go away


www.golivewire.com