Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Python codes

Posted on 2009-02-22
2
Medium Priority
?
648 Views
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:
k=k**2
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
result=0
return result.sum

0
Comment
Question by:Student_101
2 Comments
 
LVL 17

Expert Comment

by:ramrom
ID: 23707094
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

by:
Student_101 earned 0 total points
ID: 23707411
it's okay, i got it done:) thank you, and no i haven't had much success.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

580 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