4 Replies - 1111 Views - Last Post: 03 October 2012 - 05:47 AM Rate Topic: -----

#1 kehara15  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 13-September 12

While loops assignment

Posted 26 September 2012 - 11:49 AM

This is the assignment I am given from my professor

Write a function SumofEvens. This function must have one input argument that is a list of integers.
1) Calculate the sum of even numbers in the input list using while loop
2) Return the sum of even numbers contained in the input list

So far I know that I start like this:

def SumofEvens()


In the parenthesis it is saying that the function must have one input argument that is a list of integers. What is an input argument?

Is This A Good Question/Topic? 0
  • +

Replies To: While loops assignment

#2 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7562
  • View blog
  • Posts: 12,680
  • Joined: 19-March 11

Re: While loops assignment

Posted 26 September 2012 - 11:57 AM

Read here. Grab some tutorials (slide your eyes to your right a little) Shake the google tree a little.

Sorry, but you're going to have to at least pretend to try a little.
Was This Post Helpful? 1
  • +
  • -

#3 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: While loops assignment

Posted 26 September 2012 - 10:07 PM

An input argument, or parameter, is the data required for your function to run. For example, if I wanted to write a function that would take someone's age and return their age in dog years, I might want to have their age as a parameter.

If you have any further questions, show us your progress with your code. We give much more help when the OP shows much more effort.

This post has been edited by atraub: 26 September 2012 - 10:07 PM

Was This Post Helpful? 0
  • +
  • -

#4 Failor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-September 09

Re: While loops assignment

Posted 27 September 2012 - 06:49 AM

the while loop works while some condition is true so it should look something like that:

def sumEven(lst):
    While <condition( n your case even numbers)>:
       <the action to be performed>
       return <the product of the action above>


Also you need a string that requests a user for the input (list of numbers in your case)
and then sends this string into the function.
Was This Post Helpful? 0
  • +
  • -

#5 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: While loops assignment

Posted 03 October 2012 - 05:47 AM

View PostFailor, on 27 September 2012 - 01:49 PM, said:

Also you need a string that requests a user for the input (list of numbers in your case)
and then sends this string into the function.


From what OP says, he doesn't have to worry about user input. He just has to write the function.

kehara15, you're going to need to read up on functions. Here's a fairly good tutorial on the topic. I recommend typing in the code as you read through it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1