LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 800 users online 223882 members 1359 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
grinchilla
I haven't filled out my profile...
Mood: Flirty
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
5 online / 42 MPM
Fresh Topics
  LiveWire / Technical Forums / Computer Virus & Anti-Virus Software / Adding Reply

Quoting Post
Archived Topic: It will not be bumped to the top of the forum.
Topic Problem with code
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
tiara Posted 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??

Replies
matto Posted at 5:54 am on Nov. 14, 2008
if you do your calculation or output or whatever before incrementing, the problem will go away
Wii Tard Posted at 5:38 am on Nov. 14, 2008
this reminds me of VB....i hate it
Tubbz Posted at 5:36 am on Nov. 14, 2008
for less than 10, it gives n=9 and n+2 (11)
allsmiles Posted at 5:32 am on Nov. 14, 2008
<9, not <10.
glovd001 Posted at 5:22 am on Nov. 14, 2008
Post from this position was omitted due to content violations
bigdutchman Posted 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.

All 6 previous replies displayed.