The goal is to learn to use some basic Python functions and SageCell.
Basics
In this section we cover some basic Python syntax.
- (a)
- The print command prints variables and strings to the screen.
- (b)
- Comments let you insert text into your code that is not executed. This will help to remind you (and others) what your code does.
- (c)
- Lists help you organize and manipulate data.
- (d)
- Mathematical functions like , have to be imported from another file. Use this link for more information.
SageCell
A SageCell is a web-interface where you can type in Python code and evaluate it without installing any special software or navigating to another page. SageCell runs a special version of Python 3 with some minor differences to the standard kernel. This should not present any serious difficulties in this course. Each problem in the next section has a SageCell after it. Be sure to type in your answer to each problem in the appropriate SageCell.
Below is an example of a SageCell. Click on the ‘Evaluate’ button to see the result.
Problems
- (a)
- Print a string that contains your full name.
- (b)
- Print the length of the string from the previous question. (Hint: Strings are lists where each element is a single character.)
- (c)
- Compute and print . Are you surprised by the result?
- (d)
- Compute and print .
- (e)
- Are the trigonometric functions assuming that the input is in degrees or radians?
- (f)
- Compute and print . (Hint: You will need to find an appropriate function using the math library link above.)