Starting from:

$24.99

MIT60001 Problem Set 0 Solution

This problem set will introduce you to the programming environment Spyder from the Anaconda Distribution of Python, and to programming in Python, as well as to our general problem set structure. In this problem set, you will confirm your installation of Python, write a simple Python program, and hand it in. Be sure to read this problem set thoroughly, especially the Collaboration and Hand-in Procedure sections.
Collaboration
Installing Python and Spyder
Follow the steps in the Getting Started handout for installing the Anaconda distribution of Python and Spyder onto the machine you plan to be using this term. The numpy and matplotlib packages, which will be used primarily in 6.0002, should come with the installation.
Familiarize yourself with Python and Spyder using the exercises given in the handout.
Once you are ready, proceed to the programming part of this assignment.
Note, when you first start using your system, make sure that the version number displayed is
3.0 or higher. This version of Python is not backwards compatible with versions starting with
2.x.
This class uses Python version 3.5 or higher.
A Very Simple Program: Raising a number to a power and taking a logarithm


The goal of this programming exercise is to make sure your python and numpy installations are correct, to get you more comfortable with using Spyder, and to begin using simple elements of Python. Standard elements of a program include the ability to print out results (using the print operation), the ability to read input from a user at the console (for example using the input function), and the ability to store values in a variable, so that the program can access that value as needed.
Assignment:

Write a program that does the following in order:

1. Asks the user to enter a number “x”
2. Asks the user to enter a number “y”
3. Prints out number “x”, raised to the power “y”.
4. Prints out the log (base 2) of “x”.


Use Spyder to create your program, and save your code in a file named ‘ps0.py’. An example of an interaction with your program is shown below. The words printed in blue are ones the computer should print, based on your commands, while the words in black are an example of a user's input. The colors are simply here to help you distinguish the two components.
Enter number x: 2
Enter number y: 3
X**y = 8 log(x) = 1




Hints:

statements to print out values of variables.
● Reference the basic math section of the Python Wikibook to read more about using basic mathematical operators in Python

MIT OpenCourseWare https://ocw.mit.edu
6.0001 Introduction to Computer Science and Programming in Python
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.

More products