A document from MCS 260 Fall 2021, instructor Emily Dumas. You can also get the notebook file.

MCS 260 Fall 2021 Worksheet 1

  • Course instructor: Emily Dumas

Topics

This worksheet covers software setup for MCS 260 and number systems.

In general, the MCS 260 worksheet for any week's lab will cover material up to the Monday of that week; for week 1, this means only lecture 1 is included.

Instructions

  • Work on the activities below in lab.
  • Seek assistance from your TA or from fellow students if you run into trouble.
  • Start on the software setup tasks, but skip ahead to the number systems exercises if it looks like you are running out of time. It's important to get practice on both while you have a TA and other students around to offer support and assistance.

Collaboration

Collaboration on worksheets is strongly encouraged.

Resources

The main course materials to refer to for this worksheet are:

(Lecture videos are not linked on worksheets, but are also useful to review while working on worksheets. Video links can be found in the course course Blackboard site.)

Part I: Software setup

These instructions assume you'll use a personal computer to do some of your coursework, and that you brought this device to lab with you.

If you are going to use UIC lab computers exclusively, and not do any course work on a personal device, you shouldn't need to install anything. Instead, follow the instructions below but skip the actual install steps, so that they become a series of checks that everything is working and that you know how to run it.

All of the software you need for MCS 260 is free. No purchase is required.

1. Install Python 3.9 (or any version 3.6 or higher)

The exact steps depend on the operating system of your computer (Windows, MacOS, Linux), and details can be found in the Getting Started section of the course web page.

For most students, this step either requires no action (recent MacOS) or is as simple as opening the Microsoft Store, finding Python 3.9, and clicking Install (Windows).

2. Open a terminal

We'll do a lot of work in MCS 260 using a text-based interface to your computer, the terminal.

The terminal is an application like any other, and is already installed on your computer. But the name depends on your operating system:

  • In Windows, you need to run Windows Powershell. Look for it in the Start Menu. It should open a window with a dark blue background. We recommend making a shortcut to this application on the desktop or in the taskbar, since you'll need to use it a lot.
  • In MacOS, run the application Terminal, which is located in the Applications menu under the submenu Utilities.
  • In Linux (with a graphical desktop), the name depends on the distribution and desktop environment. You'll need to open the application menu or launcher and look for a terminal application.

At the end of this step, you should have a window open that displays a small amount of text, and which is waiting for keyboard input.

3. Run the Python 3 interpreter in the terminal

To do this, you'll need to make the terminal the active window and then type the interpreter command name followed by the Enter key. The interpreter command name could be either python3 or python, and in some cases both will work. Try them in that order.

Success looks something like this:

PS C:\Users\ddumas> python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Notice the Python 3.9.6 on the second line, which shows that Python 3.9 is running. If you see something like Python 2.7.18 instead, it means that command opened a much older version of Python that cannot be used in MCS 260. Try the command python3 instead.

At this point your terminal will be "stuck" in Python, which waits for you to type commands. You can tell that you are in Python because the prompt is >>>. If you needed to exit from Python, you would use the command exit(), but we'll stay in Python for the next step.

4. Run the traditional first Python statement

This step assumes you have a terminal running, and Python 3.x is running inside that terminal. You should see a prompt >>> with the cursor to the right of it.

Type the traditional first Python statement

print("Hello world!")

followed by the Enter key. Be careful to include the quotation marks and parentheses exactly as shown above. If you succeeded, a new line of text should appear that contains simply

Hello world!

At this point, you can exit Python by typing exit() followed by the Enter key.

5. Install a programming editor

Most students entering MCS 260 either won't have a programming editor installed, or else won't have a strong opinion about which one is best. If that applies to you, then you should install our recommended one, Visual Studio Code. It's a free program by Microsoft available from this URL:

Note that Visual Studio Code is very different from Visual Studio. Both are made by Microsoft, but we'll only use the first one.

If you already have a different programming editor installed, and prefer to use that, you may do so. However, we probably can't offer technical support on other editors.

Also, programs like Microsoft Word (on Windows) or Pages (on MacOS) are document editors, not text editors, and they won't work for MCS 260.

6. Create a file in Visual Studio Code

Open Visual Studio Code (from the start menu or application launcher) and create a new file. You can use Control-N or select File>New from the menus.

In that file, type the following text:

print("Hello world, this is a script!")

Save the file on the desktop (Control-S or File>Save), giving it the name hello.py. The extension .py identifies this file as a collection of Python statements, i.e. a script.

7. Find the desktop in the terminal

Switch back to the terminal or open it again, as applicable. Change the current working directory to the Desktop. In most terminals, the following command will do that:

cd ~/Desktop

8. Run the script you created

Run the script hello.py that you created in step 6 by typing the command

python hello.py

or

python3 hello.py

in the terminal. Success is indicated by

Hello world, this is a script!

appearing after you press Enter.

Note 1: This command needs to run in the terminal, and not in Python itself. If your terminal shows >>> next to the cursor, it means Python is running and you need to exit. The command exit() will exit Python and return to the terminal.

Note 2: This simple script will run properly even if you accidentally use the Python 2 interpreter. In the future, however, running scripts related to MCS 260 under Python 2 will create major problems. Thus it is important to make sure you are actually running Python 3. You can edit the script hello.py to add a check, as follows:

import sys
print("Hello world, from Python version",sys.version)

This will print a greeting that includes the Python version. For example, on Windows it might show:

Hello world, from Python version 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32

9. Experiment with Python as a calculator

Run python in the terminal again, to get the >>> prompt. Now, experiment with using it as a calculator. For example, try these commands:

  • 2+3
  • 2*36
  • 2**5
  • 11/2

Part II. Number systems

Work out these number conversion problems by hand. This document doesn't provide space to write, so use a separate sheet of paper, a blank page in your tablet's writing application, etc.. If you can figure out a way to check them with a calculator or with Python, do so afterward, but this isn't required.

The purpose of working a few conversions by hand is to make sure you understand the basic principles of different number systems.

10. Convert 0b010110001 to decimal.

11. Convert 0xB00 to decimal.

12. Convert the decimal number 99 to hexadecimal.

13. Convert 0b10010110 to hexadecimal.

14. Convert the decimal number 56 to binary.

15. What is the decimal value of the largest number that can be written with 2 hexadecimal digits?

16. Which is bigger: The largest number you can write in decimal with 4 digits, or the largest number you can write in binary with 13 digits?

Revision history

  • 2021-08-21 Initial release