13,201,452 members (72,968 online)
Rate this:
See more:
Write a for loop that sums the values 1 through end, inclusive. end is a variable cannot Use A Variable Called 'sum'

"end" to be 6, your code should print out the result:
21
which is 1 + 2 + 3 + 4 + 5 + 6.

do not include raw_input statements or define the variable end. so write your code in the following box assuming end is already defined.

MY CODE.. "end" variable is already defined, so cannot define it..

total = 0
index = 1
for i in index <= end:
index += 1
print (total)
Posted 22-Feb-13 17:02pm
Valmach150
Updated 22-Feb-13 18:10pm
v2

Rate this:

## Solution 1

question one : why python 2.7 ?
question two : please be clear on what you need to achieve with your code

"in order to get right answer u need to ask right question"
Valmach 23-Feb-13 0:08am

does not necessarily have to be 2.7. but that's what i am learning on. As a beginner student I am trying figure out why if the variable "end" has been "predefined, and cannot use the variable sum or enter "raw_data" as a matter of fact no built-in functions are allowed.. the code should get = 21 without using "built-in" functions - so.. i tried the code above and when the Teacher checks.. Wrong answer. .I hope this explains the situation better
Creepystranger 25-Feb-13 0:49am

although still not very clear to me but if i am correct ur trying to suggest that u need to write a code which will add upto the "end" where end is predefined and u can not use any variable like sum for adding numbers

what i understand from ur question that u do not want to use any other variable like total so

i would suggest u to forget the for loop and use math's simple algorithm

1+2+3....+n= n(n+1)/2 .
Valmach 25-Feb-13 1:32am

As described to me..
Write a for loop that sums the values 1 through end, inclusive. end is a variable. the defined end is to be 6, code should print out the result:

21
which is 1 + 2 + 3 + 4 + 5 + 6.

do not include raw_input statements or define the variable end. - so write code assuming end is already defined.

Don't Use A Variable Called 'sum'
Valmach 25-Feb-13 1:32am

also must use a For Loop

Top Experts
Last 24hrsThis month
 OriginalGriff 300 Richard MacCutchan 125 Dave Kreskowiak 80 GKP1992 75 Karthik Bangalore 70
 OriginalGriff 8,060 ppolymorphe 2,014 Karthik Bangalore 1,724 CPallini 1,208 Jochen Arndt 1,075