Ask Your Question
0

How can I find the sum of first 20 positive perfect square?

asked 2018-08-10 08:57:42 -0500

pizza gravatar image

updated 2018-08-21 00:22:10 -0500

Hi! First post!

When I type " k^2 for k in [1..20] ",

it says

" k**Integer(2) for k in (ellipsis_range(Integer(1),Ellipsis,Integer(20))) ^ SyntaxError: invalid syntax "

What can I type?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2018-08-10 10:51:25 -0500

slelievre gravatar image

Note that you can use (1 .. 20) to iterate through the integers from 1 to 20, without constructing the list of these integers, as [1 .. 20] does.

To obtain an iterator of squares:

 sage: (k^2 for k in (1 .. 20))

To obtain the list of squares:

sage: [k^2 for k in (1 .. 20)]

To obtain the sum of squares:

sage: sum(k^2 for k in (1 .. 20))
edit flag offensive delete link more

Comments

Thank you for answering.

pizza gravatar imagepizza ( 2018-08-11 09:39:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-08-10 08:57:42 -0500

Seen: 69 times

Last updated: Aug 21