I would like to stress that this is for personal practice and nothing school or assignment related.
Create a function countPages(x) that takes the number of pages of a book as an argument and counts the number of times the digit '1' appears in the page number.
(topic 5 - q 4 at pyschools.com)
def addNumbers(x): finalsum = list() theSum = 0 i = 1 while i <= x: theSum = theSum + i i = i + 1 finalsum.append(theSum) return finalsum
I'm a beginner and I cannot seem to understand the reason of two things:
1) I'm trying to understand how to make it calculate the entire sum and produce one output. for example addnumber(10) = 55. with me it shows all the lists, and even if i do splicing (-1] it doesn't work.
2) why do I recieve a different output when i use "return" and "print" in this function?
could somebody please guide me through understanding this question? these concepts?
Thank you kindly.