LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 326 users online 225234 members 184 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
iamironman
Cool Things: Cubes. Guitars. Didgeridoos.
Mood: Excited
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
3 online / 19 MPM
Christmas!
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,892 | Points: 5,554
LiveWire Humor
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: 364
Join to learn more about bigdutchman Washington, United States | Straight Male | Posts: 1,769 | Points: 5,563
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: 591
Join to learn more about allsmiles England, United Kingdom | Male | Posts: 9,109 | Points: 16,357
Tubbz


Guru

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

-------
I came on Eileen
2(✈) + 2( ▌) = -3017

Intelligence:Confusing Americans since MDCCLXXVI

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


Soothsayer

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

-------
-

5:38 am on Nov. 14, 2008 | Joined: May 2005 | Days Active: 395
Join to learn more about Wii Tard South Carolina, United States | Bi-curious Female | Posts: 7,492 | Points: 11,919
matto

Enlightened One

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

-------
"Say what you like about the tenets of National Socialism, Dude,
at least it's an ethos."
--Walter Sobchak

5:54 am on Nov. 14, 2008 | Joined: Aug. 2007 | Days Active: 496
Join to learn more about matto California, United States | Male | Posts: 9,856 | Points: 15,601
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