Montana Tech of The University of Montana
Computer Science Department

CSCI 135
Fundamentals of Computer Science I
Fall 2021



LAB ASSIGNMENT 0

The goal of this assignment is to introduce you to programming in Python. You will learn how to write, compile, and run your own programs. You will become familiar with some basic features of the IDLE Editor and the Python Shell.


Part 0: Hello new world!
As is traditional, your first Python program is the Hello world program. In this part, you will develop a program HelloNewWorld.py that displays something different from "Hello world!". What you display is up to you - keep it nice. :) If you are working from home or on your own laptop, first set up Python as described on the resources page. Since this is your first time using the Idle editor and shell, we'll show you step-by-step what to do.

0) Start by launching Idle. On lab machines, go to the search bar at the bottom left, and type Idle. Select Idle 3.9.6 or its equivalent. This will bring up the Python Shell window, which will look similar to the image below.


In the shell window, you can type Python commands and see the result immediately. Try typing in: print("Hello World!") and then press the Enter key. Remember, this is a programming language, so you have to be very precise in what you type - Python will not understand typos. You can also try typing in some math equations and use the shell as a calculator. Try typing in 3+4 and 3+4*3 and (3+4)*3, pressing the Enter key after each.

The >>> symbol in the shell where you type your commands is called the prompt. It's just a symbol that lets you know you can type in instructions at that point.

1) Select File -> New File from the top menu in the shell. This brings up an editor window where you can write your own programs and save them. Your program will be a list of Python statements that you will save and then run, or execute. Here you can type in the statements that make your program run as you want it to.


2) You can now start adding code to your file. In the screenshot below, note how I've added the required header comments at the top. We require headers on every source file you submit in the course so you want to get in the habit of doing this. You will be docked points if you don't. You'd be surprised how quickly in real-world programming you forget what a program you wrote does. Providing a good descriptive header is a good habit. It also helps us keep track of who turned in what when we grade your labs.


3) Before you can actually compile and run your program, you will have to save it. Select File -> Save from the top menu. You will need to tell Python where to save your work. We strongly recommend a flash drive or cloud drive because it is not guaranteed that your program will stay on the computer you're using next time you're in lab, and you may not be able to retrieve your work.

Save this particular program with the name HelloNewWorld.py. We will tell you what you should name your program files, and as programs get more complex, this will become more important. Pay attention to how the program name is capitalized.

Once you've saved your file, you can compile and run it. Select Run -> Run Module from the top menu, or alternatively, press the F5 key (top row of the keyboard). Your program will be compiled and will then run in the Python shell window.

 


Part 1: Greetings
Create a program Greetings.py that introduces yourself. This program will make use of an escape character. We will cover what an escape character is at a later date, let's just try one out for now. The one we will use is called a new line. To use it, we add \n in our string.
In the IDLE Shell try entering in print("Goodbye\n cruel \nWorld"). Pay attention to where the spaces are and where the new lines are. Play around adding more \n characters in different spots and in a row.


0) This program should have two sections of output. The first section should be you introducing yourself. Example "Hello, my name is Baby Yoda."

1) The second should be something about yourself. Something like hobbies, favorite foods, where you are from, etc. These two sections should have 2 blank lines between them. See the example below.

 


Grading Each of the programs is worth 10 points each, for a total of 20 points. For each program, you will be graded according to the following criteria:

Grade ItemHelloNewWorldGreetingsPoints Earned
Program Compiles and Runs
2
2
Header Comment
2
2
Program Runs Correctly
4
4
Correctly Formatted Output
2
2


Submission. Submit both programs HelloNewWorld.py and Greetings.py via the Moodle dropbox for Lab 0. Please don't "zip" them - just submit them as two files. Be sure each submitted source file has the required header with your name and a description of the program.

Page last updated: August 31, 2021