Python codes

Posted on 2009-02-22
Last Modified: 2013-11-05
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:
return total

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
return result.sum

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?

    Accepted Solution

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    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…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now