1 Replies - 230 Views - Last Post: 19 November 2015 - 07:28 AM Rate Topic: -----

#1 ssomers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-November 15

Using a function to add numbers

Posted 19 November 2015 - 07:25 AM

Hi there, I'm very new to Python, trying to figure it out with tutorials and such.

An exercise I'm trying to do involves defining a function where, when the variable is given, will print the sum from 1 - the variable.

ie:

[code] def summed(x) [code]

if x is replaced with a number, it will add all numbers from 1 - x.

I'm also meant to be using a for loop within the function.

I don't necessarily want the solution, but how should I approach this? Should I be using a range?

Is This A Good Question/Topic? 0
  • +

Replies To: Using a function to add numbers

#2 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • Posts: 2,322
  • Joined: 13-June 14

Re: Using a function to add numbers

Posted 19 November 2015 - 07:28 AM

Write the function how you think it should be written. Using range() sounds sensible. Try something out and see if you can get it to work. Then, if you find a problem that you can't fix, post your code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1