Mini Sage Introduction

Here’s a very basic intro to Sage. In each of the cells on this page, you can alter the code and see how it changes the output. Play around!

You can ask it to do basic math:

 

You can assign things (like numbers) to variables. Use * for multiplication and ^ for exponent:

 

It didn’t look like it did anything, but if you want to see what is inside the variable n now, you just type the variable name:

 

Keep in mind that this depends on you executing the cells in the order I’ve presented them!

One way to do things to variables is to use inbuilt functions:

 

You might also use this syntax:

 

Lists are very useful in sage. A list is an ordered collection of things.

 

One important skill is to modify the elements of a list by some fixed action. Guess what this does before you evaluate:

 

As far as programming goes, the for loop is a central tool. This tells the computer to do something repeatedly, once for each member of a list. Guess what the following example does before you try it.

 

Here’s a sandbox for you to try things: