Python
Homework 1 ● Note: Plagiarism is serious. Please only submit your own work from your own computer.
○ Googling is encouraged. ○ Independent work only. ○ Helping each other install python is encouraged. ○ Running code for others is wrong.
● Feel free to email me or TAs, all emails on Blackboard, the "Announcement" section ● Submit electronically to Blackboard For this homework, you're asked to upload some screenshots, a text file
named "homework1.txt" (or another text suffix, doesn't have to be txt), and a python file named "test.py". See blue font below. You can zip everything into 1 file, or just upload individual files.
Task 1 -- Python Installation & Hello World
Description Install Python 3.8.x, understand how to get into the Python shell. Python shell is a quick way to test code snippets and perform quick testing, it's crucial to know how to open it, how to use it, and how to exit.
Requirement ● Display Python version. There are a few ways to know the version, of which "python3 --version" is probably the
easiest way. Attach a screenshot that shows your Python version, using any method. (Why do we care about the Python version? Each newer version is slightly (or vastly) different from the previous version, for basic stuff, Python keeps backward compatibility and things behave more or less the same. Still there might be some differences here and there, it's good to be aware of versions early on)
● Print "Hello World!" in python shell. Attach a screenshot that shows how you get into the python shell, and print "hello world!" to screen, then show how you exit. (Hello world is a typical first step in programming. For python it's ealy, 1 line. As compare to Java, we'll have to learn to create a class first. )
Example screenshots Please ignore my older python versions, your version should be 3.8.x
Task 2 -- Install Pandas, Numpy, Matplotlib, Seaborn
Description Install Pandas, Numpy, Matplotlib, Seaborn, then provide screenshots to show success. You can use terminal to run "pip3 install xxx" or "pip install xxx" on some systems, or install inside of PyCharm, feel free to google how to do that.
Requirement
● For pandas: ○ login to python shell and do “import pandas; dir(pandas)” similar to what I show in the example below.
Your screenshot doesn’t have to include the full content of ‘dir(pandas)’ if it’s too long. Please attach a screenshot.
○ Please describe what builtin function "dir()" does, using <100 words, the shorter the better. Write to homework1.txt file.
○ Please try using "dir()" on another builtin function we just learned. Attach screenshot.
● For numpy: ○ Command line “one-liner” to do the same task as for pandas above. See example below.
python3 -c "import numpy; print(dir(numpy))". If "python3" doesn't work, use "python". Attach screenshot. ○ Please google, then describe what "python3 -c" (or "python -c" does, use <100 words or as few as
possible. Write to homework1.txt file. (Why do we ask about this: Googling is a must when it comes to programming.)
Example Screenshots
Task 3 -- PyCharm | Text Editor
Description For any programming, you will need a text editor. PyCharm is commonly considered the best when it comes to Python. Other choices include: Sublime, emacs, vi (or vim). If you want to challenge yourself, try vim.
Requirement ● Use PyCharm (or other editor), to create a python file called "test.py". In this file, let's put a simple line "print
'Hello world!'" in it, or anything simple of your preference. The actual code doesn't matter much, as long as it prints something to screen.
● Please run this code inside of PyCharm. Attach a screenshot that shows the code as well as the running result. If you use another editor that can't run Python, skip this task.
● Find this file on your computer, and submit the file to blackboard. The actual file content may vary, the purpose of this task is to find the file.
● Command line running python code: find the file you just wrote, and run it on command line using "python3 test.py", or with the full path: "python3 /User/xxx/PycharmProject/yyy/test.py". Attach a screenshot showing how you run it, and the result. (why do we need to command line run python code, don't we have pycharm that does everything for us? Yes, pycharm is great and I love it too, yet we may not always have pycharm, say another computer in the office, or a remote server login using ssh. In a lot of cases, pycharm is not available and vim being the only editor available on most linux servers. Plus, "python3 xxx.py" is the official way of running python code. PyCharm is just a tool that makes things simple )