![]() |
|
#1
|
|||
|
|||
Little help part 3Just wondering anyone here can help me getting started or show me where i can read how to write this program
i have to write a program where if i put 5 it should output 55 for example, when u put 5 it will compute 1^2+2^2+3^2+4^2+5^2 and the output is 55 i got a code where its adding up all the 1 2 3 4 5 and im getting a 15 and i also got a code where it's a factorial and when i put 5 it's times all the numbers and outputs a number but i aint getting 55 |
|
#2
|
||||
|
||||
Re: Little help part 3Why don't you post your code so we can see how you're approaching the problem? I have an idea of what to do but I want to make sure it's not the same thing you've already tried.
__________________
Common Sense v2.0-Striving to make the world a little bit smarter. |
|
#3
|
|||
|
|||
Re: Little help part 3Python Code:
OK here is the code where it adds up the numbers ... but it doesn't add and times the numbers by the cude. like it does this 1 + 2 + 3+ 4+5 .. it gives me 15 but it doesn't do 1^2+2^2+3^2+4^2+5^2 = 55 .. i wrote a code but i guess i didn't save it and now I'm pissed off it's gotta be written in parameters... so i was trying this Python Code:
but it doesn't work, not sure why it's doing that but it pissing me off Last edited by admin : 08-Mar-2008 at 01:04.
Reason: Please insert your example Python codes between [PY] and [/PY] tags
|
|
#4
|
|||
|
|||
Re: Little help part 3Also if you know how to print list backwards without sorting the list .. that would be awesome.. this is what i have so far done where i got the list to print backwards but its sorting them out.. we did sort in class and i try to use the same code but it doesn't work. its sorts them but it doesn't print the way i want them to do. like for example if i put in 1 2 3 9 5 0 5 it should print 5 0 5 9 3 2 1 but instead its print 9 5 5 3 2 1 0
here is the code Python Code:
Last edited by admin : 08-Mar-2008 at 01:05.
Reason: Please insert your example Python codes between [PY] and [/PY] tags
|
|
#5
|
||||
|
||||
Re: Little help part 3Your first problem doesn't appear to have you squaring the values at any point. Isn't that a requirement? All you're doing is adding the numbers together in the range. You have to have a step where each number is squared before it is added to the sum.
For your second problem, Python has a method for reversing lists. Check out the tutorial:http://docs.python.org/tut/node7.html. You don't have to create your own method to do it, unlike C/C++, which is one of the benefits of Python. __________________
Common Sense v2.0-Striving to make the world a little bit smarter. |
Recent GIDBlog
Toyota - 2008 July Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| floating point decimal to ascii conversion | crazypal | C Programming Language | 5 | 18-Apr-2007 04:59 |
| Re: Beginning Python Tutorial (Part 8) | crystalattice | Python Forum | 0 | 02-Nov-2005 09:11 |
| Re: Things to Avoid in C/C++ -- void main(), Part 10 | WaltP | C Programming Language | 0 | 18-Oct-2005 20:25 |
| [Tutorial] Pointers in C (Part II) | Stack Overflow | C Programming Language | 0 | 27-Apr-2005 17:36 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The