Solved

# Python codes

Posted on 2009-02-22
622 Views
I need to write a short code that uses the variables  k and  total to write a  while loop that computes the sum of the squares of the first 50 counting numbers, and associates that value with  total . so the code should associate 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 with  total . This is the code i came up with, can anyone guide me as to what's wrong with it?

total=[1*1 + 2*2 + 3*3 +... + 49*49 + 50*50]
while k total:
k=k**2

2) i also need to write a code that uses a while loop that adds the integers from lo up through hi (inclusive), and associates the sum with result .

this is what i came up with:
while lo+hi=result
result=0
return result.sum

0
Question by:Student_101

LVL 17

Expert Comment

1 - This sounds like homework. We don't solve homework problems. We can help with specifics when you make an attempt and get stuck.

2 - "what's wrong with it" - why do you think something is wrong. It helps a lot if you tell us what you expect and what you get. If there is an exception, post the traceback.

3 - It appears that you don't understand Python syntax (or programming concepts in general?). Have you had success running any Python programs? Do you understand the syntax of while statements?

4 - Could you benefit from using for and range in problem 1?
0

Accepted Solution

it's okay, i got it done:) thank you, and no i haven't had much success.
0

## Featured Post

### Suggested Solutions

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…