Problem Set 0: Introduction & Installation
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Freshman Sophomore Junior Senior Graduate Student (Non MBA) MBA Student
None HTML AP Computer Science Online coding course (code academy, etc.) Programming Experience in language other than Python Programming Experience in Python Took 6.0001/6.100A before Took a Python course at MIT during IAP before (e.g. 6.145) Watched or Participated in Programming course in OCW or edX College course using programming language other than Python College course using Python
To Learn how to Program To Fulfill a Course Requirement To Get a Good Grade other
Google Online coding courses Stack Overflow Friends that know how to program
(did you read the course info page?)
problem sets mandatory exercises optional exercises on MITx exams lecture attendance and participation recitation attendance and participation
every Monday every Wednesday depends on the pset, check the calendar
generally available with the pset, and due with the pset generally available with a lecture, and due by the beginning of next lecture no deadline per exercise, but must do them all by the end of the course
Email S^3 and post to the forum to schedule a conflict microquiz Conflict microquizzes are not given but the lowest quiz grade is dropped
Yes for you and the friend Yes only for the friend Yes only for you no
Yes for you and the friend Yes only for the friend Yes only for you no
The rest of this problem set guides you through setting up your Python environment, writing a simple Python program, and submitting it on our website. Be sure to read the instructions thoroughly, especially the Collaboration and Hand-in Procedure sections. Your submission will not be graded, but subsequent problem sets will rely on this understanding.
You may work with other students, but each student should write and submit their Python program individually. For details, refer to our Collaboration Policy in Section 6 of the course info page. Be sure to indicate those whom you worked with in the comments near the top of your submission.
The Getting Started handout (found in the zip file above) provides instructions for installing the Anaconda Distribution of Python and using the Spyder integrated development environment (IDE) that comes with it. You are not required to use Anaconda or Spyder, but we recommend this setup for first-time programmers, due to the ease of installation and the bundled packages. Alternatives to Spyder include VSCode and PyCharm, but we do not officially support them (yet).
This class uses Python version 3.6 or higher. No matter what setup you use, make sure the version number displayed in the Python terminal/console meets that requirement. (And you should definitely avoid Python 2.x, as Python 3 is not backwards compatible.)
If you choose not to use Anaconda, make sure you also install the following Python packages, typically through pip
:
- matplotlib
- numpy
- pandas
- scikit-learn
- Pillow
Otherwise, these are all included when you install Anaconda. Familiarize yourself with basic Python and the Spyder IDE using the exercises in the handout. Once you are ready, proceed to the programming task below.
The goal of this exercise is to get you comfortable using simple elements of Python.
Such elements include the ability to print out results (using the print
operation), the ability to read input from a user at the console (using the input
function), and the ability to store values in variables, so that the program can access those values as needed.
In the file named ps0.py, write a program that does the following in order:
- Ask the user to enter a number
x
. - Ask the user to enter a number
y
. - Print out number
x
, raised to the powery
. - Print out the log (base 2) of
x
.
An example run of the program is shown below.
The numbers printed after :
are instances of a user's input.
The rest are should be printed by your program.
Enter number x: 2
Enter number y: 3
x**y = 8
log(x) = 1.0
Hints:
Most of the functionality you need is demonstrated in Lecture 1, and the Getting Started handout has examples of accepting input and calculating logarithms. For more examples of how to use the functions you need, see the following pages on Wikibooks and Numpy's documentation:
- Generating output
- Accepting input.
Remember that the
input()
function always returns a string, and it's your job to turn it into a number of some kind. - Arithmetic
- Log base 2 convenience function via Numpy.
(If you use this according to the examples at the bottom, you will need to include the line
import numpy as np
near the top of your file.) - Variables, strings, and numbers
Save your code in ps0.py. Do not ignore this step or save your file with a different name.
At the start of each file, in a comment, write down the names of your collaborators, and the number of hours (roughly) you spent on the problems in that part. For example:
# Problem Set 0
# Name: Steven Spielberg
# Collaborators: Kathleen Kennedy, George Lucas
# Time Spent: 3:30
... your code goes here ...
Upload your ps0.py file via the Select File button. Then click the Submit button. Refresh the page, and verify via the Download Most Recent Submission link above Select File that the correct file was uploaded.
When you upload a new file, your old one will be overwritten. You may upload new versions of each file until the 9 PM deadline, but anything uploaded after that time will be counted towards your late days, if you have any remaining. If you have no remaining late days, you will receive no credit for a late submission.