''' Purpose: To provide a basic overview to SageMath. This is a commented section. Everything in this block is commented out. Inputs: Outputs: Notes: - It is good practice to write an input and output for your code, and to comment your code throughout (for your own sake and for others who will read your code). For the purpose of this exercise and because there are many snippets of computations, the overall inputs and outputs will be left blank at this top section. -For shorter comments throughout your code, use #. - SageMath will execute code by cells. You can also select/highlight your entire worksheet and execute all the cells at once. '''
#You can ask SageMath to do basic computations in cells. After the next line, hit the execute button ("play"). For each cell of code, you can execute the code to see the output. 2+2
#You can assign things (like numbers) to variables. Use * for multiplication and ^ for exponent. n = 2*(10^7+1) print n #This line displays your output. If you don't type in this line, nothing will display.
factor(n) #There are many built-in functions, such as factor().
n.factor() #This is another example of syntax which does the same thing as the line above.
#Note that the cells run in sequence. If you try to run the following line, you will get an error because m is not defined. print m
myList = [1,2,3,4,5] #Lists are very useful in sage. A list is an ordered collection of things. print myList
#The for loop is a central tool in programming. 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. for n in range(8): print n
0
1
2
3
4
5
6
7
#In general, if you are online, go ahead and go to http://sagecell.sagemath.org/ to run short snippets of SageMath code.