Check out (clone) the code in the lab0 repository.
In the plantets.py file, add code to implement the functionality shown by the following sample run:
What do you weigh on earth? 136
On Mars you would weigh 51.68 pounds.
On Jupiter you would weigh 318.24 pounds.
- To calculate a person's weight on Mars, multiply their weight on earth by 0.38.
- To calculate a person's weight on Jupiter, multiply their weight on earth by 2.34.
- Your output must match my sample output exactly. Make sure there is a blank line in between prompting for the user's weight and displaying the results.
- Your program may use a "cast" only one time. Ask me if you don't know what this means.
- Your program may only use the print function once.
- Run the unit tests in planets_tests.py to check your solution!
Make sure that the code that you want to be graded has been committed and pushed to GitHub. Failure to do so will result in receiving no credit for the lab. Not sure if you code has been pushed to GitHub? Use a web browser, go to you GitHub account and check! Once your assignment has been graded, feedback will be automatically emailed to you.
https://docs.python.org/3/tutorial/
Python for Java Programmers: http://python4java.necaiseweb.org/Fundamentals/Fundamentals
If you want to use an IDE, you are welcome to. If you do not already have an IDE that you are familiar with, PyCharm is a good choice for Python development.
PyCharm IDE: https://www.jetbrains.com/pycharm/
Installing Python on Mac/Windows : https://www.youtube.com/watch?v=YYXdXT2l-Gg&list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU
Strings : https://www.youtube.com/watch?v=k9TUPpGqYTo&list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU&index=2
Conditionals: https://www.youtube.com/watch?v=DZwmZ8Usvnk&list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU&index=6
Loops: https://www.youtube.com/watch?v=6iF8Xb7Z3wQ&list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU&index=7
Functions : https://www.youtube.com/watch?v=9Os0o3wzS_I&list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU&index=8
Modules: https://www.youtube.com/watch?v=CqvZ3vGoGs0&list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU&index=9
Open a terminal window. To do so, from the system menu on the desktop toolbar,
select Applications → System Tools → Terminal. The Terminal program will present a window with a command-line prompt. At this prompt you can type Linux commands to list files, move files, create directories, etc. For this lab you will use only a few commands. Additional commands can be found at:
In the terminal, type ls
at the prompt and hit <Enter>. This
command will list the files in the current directory. (also know as a
folder.) If you type pwd
, the current directory will be printed (it
is often helpful to type pwd
while you are navigating directories). If
you type tree
, then you will see a tree-like listing of the
directory structure rooted at the current directory.
Create a new directory for your coursework by typing mkdir cpe202
.
Use ls
again to see that the new directory has been created.
Change into this new directory with cd
by typing cd cpe202
. To move
back "up" one directory, type cd ..
. To summarize
ls
list files in the currentdirectorycd
change to anotherdirectorymkdir
create a newdirectorypwd
print (the path of) the currentdirectory
Though these basic commands are enough for now, consider working through a Unix tutorial.
There are many options for editing a Python program. On the CSSE department machines, you will find emacs, vi, nano, gedit, sublime, and others. The editor that one uses is often a matter of taste. You are not required to use a specific editor, but we will offer some advice (and we will try to help with whichever one you choose). There is lots more information here:
http://users.csc.calpoly.edu/~akeen/courses/csc101/handouts/labs/lab1.html
The Python interpreter can be used in an interactive mode. In this mode, you will be able to type a statement and immediately see the result of its execution. Interactive mode is very useful for experimenting with the language and for testing small pieces of code, but your general development process with be editing and executing a file as discussed previously.
Start the interpreter in interactive mode by typing python
at the
command prompt. You should now see something like the following.
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
The >>>
is the interpreter's prompt. You can type an expression at
the prompt to see what it evaluates to. Type each of the following (hit
enter after each one) to see the result. When you are finished, you can
exit the interpreter by typing ctrl-D (i.e., hold the control key and
hit d).
0 +1
2 \* 2
19 // 3
19 / 3
19 / 3.0
0 // 3.0
4 \* 2 + 27 // 3 +4
4 \* (2 + 27) // 3 +4