The sum of squares (a special case of a geometric series) is given by the formula: Notice the results agree (although the right side is a float since we used division). Let's verify the formula for $N=1000$: N = 1000 The formula for the sum of integers from 1 to $N$ (also known as triangular numbers) is given by: Sum the numbers from 1 to 100: one_to_hundred = range(1,101) For example, compute the length of a list: len()Ĭompute the sum, maximum and minimum of a list of numbers: random = Python has several built-in functions for computing with sequences. Use a list comprehension to create the list from 1 to 20: numbers = Ĭreate the list of square integers from $1$ to $100$: squares = Ĭreate the periodic sequence $0,1,2,0,1,2,0,1,2,\dots$ of length 21 (using the remainder operator %): zero_one_two =
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |