LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 672 users online 211576 members 1680 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
SnowWhiteButIDrifted
You play the victim and I'll be the bad guy
Mood: Bored
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
4 online / 54 MPM
Fresh Topics
  LiveWire / Technical Forums / Computer Virus & Anti-Virus Software / Viewing Topic

Problem with code
Replies: 6Last Post Nov. 14, 2008 5:54am by matto
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( tiara )

Wealthy Hobo
Reply
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??

Post edited at 5:28 am on Nov. 14, 2008 by tiara

-------
I'm not cheap I'm broke :):):)


5:19 am on Nov. 14, 2008 | Joined: June 2005 | Days Active: 358
Join to learn more about tiara Ireland | Label Free Female | Posts: 1,893 | Points: 5,555
bigdutchman


Dairy Product Addict
Reply
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.

Post edited at 5:20 am on Nov. 14, 2008 by bigdutchman

-------
"Give a man a fish and he will eat for a day. Teach a man to fish and he w
ill sit on a boat drinking beer all day."


5:20 am on Nov. 14, 2008 | Joined: Oct. 2007 | Days Active: 291
Join to learn more about bigdutchman Washington, United States | Straight Male | Posts: 1,670 | Points: 4,725
Post from this position was omitted due to content violations
allsmiles


Enlightened One

Patron
Reply
<9, not <10.

-------
When they leave me, they're all smiles.
When they leave you, they're in tears.

5:32 am on Nov. 14, 2008 | Joined: Aug. 2007 | Days Active: 509
Join to learn more about allsmiles England, United Kingdom | Male | Posts: 8,074 | Points: 14,255
Tubbz


Guru

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

-------
I came on Eileen

5:36 am on Nov. 14, 2008 | Joined: Jan. 2006 | Days Active: 440
Join to learn more about Tubbz England, United Kingdom | Label Free Male | Posts: 10,298 | Points: 20,522
Wii Tard


Omnipotent One

Sustainer
Support Leader
Reply
this reminds me of VB....i hate it

-------
♥Grammar Nazi♥
Nur Gott kann mich beurteilen.
Join Citizens Raging Against Bohemia!!!
My Site

5:38 am on Nov. 14, 2008 | Joined: May 2005 | Days Active: 357
Join to learn more about Wii Tard South Carolina, United States | Bi-curious Female | Posts: 6,955 | Points: 19,770
matto


Enlightened One

Patron
Tech Support Leader
Reply
if you do your calculation or output or whatever before incrementing, the problem will go away

-------
"Strong am I with the Force, but not that strong.
Twilight is upon me, and soon, night must fall.
That is the way of things. The way of the Force."
--Yoda

5:54 am on Nov. 14, 2008 | Joined: Aug. 2007 | Days Active: 439
Join to learn more about matto California, United States | Male | Posts: 8,834 | Points: 16,903
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Computer Virus & Anti-Virus Software / Viewing Topic