CS1110 Lab 1 (Jan 27-28, 2015)

Similar documents
CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

CS 1110, LAB 1: PYTHON EXPRESSIONS.

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS First Name: Last Name: NetID:

CS1110 Lab 6 (Mar 17-18, 2015)

Lecture 3. Functions & Modules

Writing and Running Programs

Getting Started with Python and the PyCharm IDE

1) Log on to the computer using your PU net ID and password.

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

Lecture 3. Functions & Modules

Exploring Python Basics

CS 1110, LAB 3: STRINGS; TESTING

Lecture 1. Types, Expressions, & Variables

CS 1110, LAB 3: MODULES AND TESTING First Name: Last Name: NetID:

Not-So-Mini-Lecture 6. Modules & Scripts

CS1110 Lab 5: Practice for A4 (Mar 8-9, 2016) First Name: Last Name: NetID:

CS 1110, LAB 03: STRINGS; TESTING First Name: Last Name: NetID:

Exploring Python Basics

Lab: Supplying Inputs to Programs

Lecture 1. Course Overview, Python Basics

APPM 2460 Matlab Basics

Lecture 1. Course Overview, Python Basics

CS1 Lecture 3 Jan. 22, 2018

EXPERIMENT 1. FAMILIARITY WITH DEBUG, x86 REGISTERS and MACHINE INSTRUCTIONS

CS 1110, LAB 10: ASSERTIONS AND WHILE-LOOPS 1. Preliminaries

CS1600 Lab Assignment 1 Spring 2016 Due: Feb. 2, 2016 POINTS: 10

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

CMSC 201 Spring 2017 Lab 01 Hello World

CMSC 201 Spring 2018 Lab 01 Hello World

Computer Setup Guide for SEC301

Python lab session 1

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

EXCEL BASICS: MICROSOFT OFFICE 2010

Using the Zoo Workstations

Python Programming Exercises 1

CS1 Lecture 3 Jan. 18, 2019

Boot Camp. Dave Eckhardt Bruce Maggs

Introduction to: Computers & Programming: Review prior to 1 st Midterm

15-122: Principles of Imperative Computation

Lecture 2: Variables & Assignments

Lecture 2. Variables & Assignment

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

Lab 1 Introduction to R

Lab 1: Setup 12:00 PM, Sep 10, 2017

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Lab 1 Introduction to UNIX and C

Remote Access to Unix Machines

Temple University Computer Science Programming Under the Linux Operating System January 2017

Scheduling WebEx Meetings

Module 1: Introduction RStudio

EXCEL BASICS: MICROSOFT OFFICE 2007

Problem Set 1 Due: 11:59pm Wednesday, February 7

Summer Assignment for AP Computer Science. Room 302

Biology 345: Biometry Fall 2005 SONOMA STATE UNIVERSITY Lab Exercise 2 Working with data in Excel and exporting to JMP Introduction

Python for Non-programmers

GIAC Introduction to Security Fundamentals. Laptop and External Drive Configuration Guide Version 1.1 SEC301

Microsoft Word Introduction

Moodle 2.2 Student User Guide Accessing & Saving Files

Scheduling WebEx Meetings

Let s begin by naming the first folder you create Pictures.

Semester 2, 2018: Lab 1

CS110/CS119 Introduction to Computing (Java) Bob Wilson S-3-176

CS 1110 SPRING 2016: LAB 3: PRACTICE FOR A2 (Feb 23-24)

Genome Sciences 373: Genome Informatics. Quiz section #1 March 29, 2018

ONLINE TRAINING REFERENCE GUIDE

6.01, Spring Semester, 2008 Assignment 3, Issued: Tuesday, February 19 1

Classroom Performance System (CPS) Clickers Instructions I. CPS procedures if you choose to use all the options

Barchard Introduction to SPSS Marks

Gradekeeper Version 5.7

IT 220 Course Notes. Don Colton Brigham Young University Hawaii

Lecture 4. Defining Functions

Lesson 3 Transcript: Part 2 of 2 Tools & Scripting

CSE115 Lab exercises for week 1 of recitations Spring 2011

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

Scientific Computing: Lecture 1

CS 1110, LAB 2: FUNCTIONS AND ASSIGNMENTS

Tutorial 1: Unix Basics

CSC116: Introduction to Computing - Java

CMPS 12A Introduction to Programming Lab Assignment 7

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

>>> * *(25**0.16) *10*(25**0.16)

Variables, expressions and statements

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Programming for Engineers in Python. Recitation 1

LING 408/508: Computational Techniques for Linguists. Lecture 5

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Week - 01 Lecture - 04 Downloading and installing Python

The QuickCalc BASIC User Interface

Click on the Start Icon. Click on All Programs

History. Terminology. Opening a Terminal. Introduction to the Unix command line GNOME

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

Midterm Exam, October 24th, 2000 Tuesday, October 24th, Human-Computer Interaction IT 113, 2 credits First trimester, both modules 2000/2001

CSC116: Introduction to Computing - Java

06ESFContacts 1 message

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Lab 3a Using the vi editor

9.2 Linux Essentials Exam Objectives

Laboratory 1: Eclipse and Karel the Robot

Transcription:

CS1110 Lab 1 (Jan 27-28, 2015) First Name: Last Name: NetID: Completing this lab assignment is very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness does not matter.) This can be done any time up until the start of next week s lab (Feb 3-4). Thus, if you have trouble with a problem, then you have a week to get help from the teaching staff. If you finish before the hour is over, then you can leave early or you can work on the current assignment. Indeed, you are not required to physically attend the labs at all. Just make sure your work is checked off by a consultant. And remember this: The lab problems feed into the assignments and the assignments define what the exams are all about. 1 Files, Directories, Running Python, and Editing This handout is not the only part of this lab. In addition, we have two files for you to play with. Lab files are always located on the Labs section of the course website. For today s lab you will notice two files. hello1.py (a text-based Python script) hello2.py (a graphical Python script) Create a new directory on your hard drive and call is lab01. Put this directory on your Desktop. In future labs, you can put the folder wherever you want, but this lab is a lot easier if this folder is in your Desktop folder. Download all of the files into that directory. This lab handout has several empty boxes that prompt you to answer a question. As part of the lab, you are to write the answers to these questions inside the boxes. When you are finished, you should show your written answers to your lab instructor. Labs are graded on effort, not correctness. The instructor will ask you a few questions to make sure you understand the material and then swipe your ID card to record your success. This physical piece of paper is yours to keep. If your primary computer is a laptop, bring it to the lab to work on, as lab is an excellent opportunity to get started with Python on your machine. You should follow the instructions on the course website. Ask a consultant for help if you have problems with your installation. However, you do not need to spend lab time installing Python on your machine. If you want get started with Python now and install it later, you should work on a machine in the lab. The first part of the lab is to help you understand the tools that we will be working with this semester. Make sure that you have created the folder lab01 with the two files for this lab: hello1.py and hello2.py.

1.1 Working with the Command Shell Start the command shell for your computer. This is the Command Prompt on Windows (Located in Accessories in the Start Menu on Windows 7, and in Apps > Windows System in Windows 8), or the Terminal on OS X (Located in Utilities in the Applications folder). This program works like a Window in your operating system, allowing you to manipulate files and folders. However, it uses typed text commands instead of a mouse. Like a Window in your operating system, the command shell looks at a specific folder. We call this folder the active directory. You can use the command shell to list, copy, and move files in the active directory. You can also change the active directory of the command shell, just like you can change the current folder of a Window. When the command shell starts out, the active directory is your home directory. In both Windows and OS X, this is the folder with your name on it. Open up a Window for your home directory, and put it next to the command shell. Go back to the command shell. If you are using Windows, type dir and hit the Return key. If you are using OS X, type ls -l (that is a dash ell ) and hit the Return key. In a few words, describe what you see and how it compares to the Window next to the command shell. We want you to change the active directory to the folder lab01. If you followed the instructions above, this folder should be on your Desktop. Your Desktop is actually a folder stored inside your home directory. So the first thing to do is to move to the Desktop. To get there from the home directory, type the command (on either OS) cd Desktop and hit Return. Once again enter either dir or ls -l (depending on your operating system) into the command shell. In a few words, explain what is different this time and why. 2

Since lab01 is a folder inside the Desktop, you can now type cd lab01 and hit Return. Your active directory should now be lab01. One last time, either dir or ls -l (depending on your operating system) into the command shell and tell us what you see. To go back to the previous directory, you can use the command cd.. This should be enough to familiarize you with the command shell for now. If you want to learn more, visit the course website. 1.2 Working with Python There are two ways to run Python. One is to execute scripts, or files that contain Python commands. The other is to use Python interactively, typing in just one command at a time. The files hello1.py and hello2.py are both scripts. To run a script, you type python, followed by the name of the script, into the command shell. Type python hello1.py and hit Return. Does anything happen? 3

Now open up the file hello1.py with Komodo Edit. It is a file with just one line in it: #print Hello World! Delete the # character and save the file. Once again, run the script hello1.py by typing python hello1.py. What you do see this time? Finally, run the script hello2.py. What happens this time? To run Python interactively, type the word python by itself and hit Return. Do that now. You should see several lines of text followed by the symbol >>>. This is the Python prompt. Like the command shell, it responds to commands that you type. The purpose of the >>> is to let you know that you are currently running Python, and that you are no longer working with files and folders. At the Python prompt, type >>> 1+1 and hit Return (do not type the >>>). What happens? 4

2 Using the Interactive Mode to Learn Some Basics In is section, you use Python in interactive mode. For each example, write down what you think the result should be. Then use Python in interactive mode to find out if your mental reasoning is OK or not. If not, try to figure out why Python gave the answer that it did. Ask a staff member for clarification if necessary. Leave a paper trail of your mistakes and recoveries in the notes column as a reminder not to make the same mistakes in the future! The labs will often be like this. You are acquainted with a Python construction in lecture. You then nail down the rules associated with that construction in the lab by working examples two ways: mentally and then with the computer. 2.1 Useful Shortcuts If you press the up-arrow key, you get the previous expression that you typed in. Pressing up-arrow repeatedly scrolls through all the expressions that you have typed this session; if you go too far back, you can press the down-arrow key to get to a later expression. The left and right-arrow keys move the text cursor on a single line. Using all of these keys together, you can take a previously-used expression, modify it, and try it again. 2.2 Integer and Float Arithmetic Expression I Think the Value Is Python Says Notes 1 10/4 2 10./4 3 float(10/4) 4 1.0 + 10/4 5 1 + 10/4. 6 int(10/4) 7 int(3.14159) 8 float(int(10.)/4) 9 int(float(10/4)) 10 1.0/3.0 5

Expression I Think the Value Is Python Says Notes 11 10 % 4 12 4 % 10 13 9**2 14 9**.5 15 9**(1/2) 16 4**3**2 2.3 Strings Reproduce this example of string slicing by entering the first two commands >>> s = abcdef >>> s[0:3] abc Now look at these other examples Expression I Think the Value Is Python Says Notes 1 s[1] 2 s[0] 3 s[1:2] 4 s[0:2] 5 s[:3] 6 s[3:] 6

2.4 Strings and Numbers Reproduce this dialog : >>> s1 = 12.34 >>> 2*float(s1) 24.68 >>> 2*int(s1[0:2]) 24 >>> s2 = str(12) >>> s2+s2 1212 >>> s3 = str(12.34) Now look at these other examples Expression I Think the Value Is Python Says Notes 1 s2+s2+s2 2 float(s1[2:4]) 3 s3[2] 4 s3+s3 2.5 Errors If you do something illegal, Python complains. Roughly, it tries to tell you the type of error and where it occurs. In time, you will learn how to decipher error messages. For now, let s ignore the where it occurs part and interpret the rest of the message. 1. If I enter >>> 10(5+6) = x then here is what Python tells me and why it is complaining: 2. If I enter File "<stdin>", line 1 SyntaxError: can t assign to operator In an assignment statement, the expression has to be to the right of the =. >>> s = abcdef >>> c = s[7] then here is what Python tells me and why it is complaining: 7

3. If I enter >>> s = abc >>> t = s - s then here is what Python tells me and why it is complaining: 4. If I enter >>> s = abc >>> t = s(2) then here is what Python tells me and why it is complaining: 8