CS 1110, LAB 1: PYTHON EXPRESSIONS.

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

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

CS1110 Lab 1 (Jan 27-28, 2015)

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

Lecture 1. Types, Expressions, & Variables

Lecture 1. Course Overview, Python Basics

Lecture 1. Course Overview, Python Basics

CS 1110, LAB 2: FUNCTIONS AND ASSIGNMENTS

Valuable points from Lesson 6 Adobe Flash CS5 Professional Classroom in a Book

Lecture 2. Variables & Assignment

QUICK EXCEL TUTORIAL. The Very Basics

Part 6b: The effect of scale on raster calculations mean local relief and slope

Welcome to CS61A! Last modified: Thu Jan 23 03:58: CS61A: Lecture #1 1

CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS 111X - Fall Test 1

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

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

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Tutorial 1: Unix Basics

Creating an Excel resource

Lecture 2: Variables & Assignments

CMSC 201 Computer Science I for Majors

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

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2

EECS 183. Week 3 - Diana Gage. www-personal.umich.edu/ ~drgage

Table of Contents Headings:... 2 Changing text to a heading... 2 Modifying Style settings for current and future documents... 2

UAccess ANALYTICS Next Steps: Creating Report Selectors

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

Getting started with Java

ASCII Art. Introduction: Python

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

MITOCW watch?v=0jljzrnhwoi

EXCEL BASICS: MICROSOFT OFFICE 2010

Lecture 1. Course Overview Types & Expressions

CSE 131 Introduction to Computer Science Fall Exam I

Teacher Activity: page 1/9 Mathematical Expressions in Microsoft Word

Intro. Scheme Basics. scm> 5 5. scm>

Architectural Engineering Senior Thesis CPEP Webpage Guidelines and Instructions

Rio Hondo Prep Computer Applications Class

What you get When you install Python for your computer, you get a number of features:

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Python for Non-programmers

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

ECSE-323 Digital System Design. Lab #1 Using the Altera Quartus II Software Fall 2008

INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

Boolean Expressions. Is Equal and Is Not Equal

Introduction to Programming Style

CS 190C: Introduction to Computational Thinking

Boolean Expressions. Is Equal and Is Not Equal

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

CSC 101 Spring 2010 Lab #8 Report Gradesheet

The 21 WORD . That Can Get You More Clients. Ian Brodie

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block

Interactive Tourist Map

Module 1: Introduction RStudio

Document Imaging User Guide

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

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University


Window Server 2012 Hyper-V Virtual Machine Snapshots

Promo Buddy 2.0. Internet Marketing Database Software (Manual)

CheckBook Pro 2 Help

Your . A setup guide. Last updated March 7, Kingsford Avenue, Glasgow G44 3EU

Worldox GX Cheat Sheet

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:

INTViewer Tutorial Cube Tutorial

Cell to Cell mouse arrow Type Tab Enter Scroll Bars Page Up Page Down Crtl + Home Crtl + End Value Label Formula Note:

EXCEL BASICS: MICROSOFT OFFICE 2007

Statistics Winter Tutorial 1. The following computer labs have machines which support Minitab/win Release 16:

cs1114 REVIEW of details test closed laptop period

7. (2 pts) str( str( b ) ) str '4' will not compile (single, double, or triple quotes

Quick Start Editors Guide. For Your. MyVFW WebSite

ECHO HMIS FREQUENTLY ASKED QUESTIONS BASED OFF OF WEBINAR AND NEW ROI

CISC-124. Casting. // this would fail because we can t assign a double value to an int // variable

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

Chapter 1 - What s in a program?

Using the City of Stamford / Stamford Public Schools. Web System

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

(0) introduction to the course. how to learn a programming language. (0) course structure

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

CS 1110, LAB 12: SEQUENCE ALGORITHMS First Name: Last Name: NetID:

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

CMSC 201 Fall 2018 Lab 04 While Loops

NCMail: Microsoft Outlook User s Guide

KASBO Fall 2014 Session 4T Excel for Munis Accounts Payable and Purchase Orders (Lab) Presenter: Sheila Miller, KDE Business Analyst

CS111: Intro to Computer Science

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

CS 115 Lecture. Boolean logic Taken from notes by Dr. Neil Moore

Using Excel to Troubleshoot EMIS Data

Part III Appendices 165

Learning Objectives. Description. Your AU Expert(s) Trent Earley Behlen Mfg. Co. Shane Wemhoff Behlen Mfg. Co.

Setting up Python 3.4 and numpy and matplotlib on your own Windows PC or laptop

Petrel TIPS&TRICKS from SCM

A lot of people make repeated mistakes of not calling their functions and getting errors. Make sure you're calling your functions.

Transcription:

CS 1110, LAB 1: PYTHON EXPRESSIONS Name: Net-ID: There is an online version of these instructions at http://www.cs.cornell.edu/courses/cs1110/2012fa/labs/lab1 You may wish to use that version of the instructions. This lab serves two purposes. First, it is designed to get you started with Python immediately. Second, gives you hands on experience with Python expressions, which we talked about on the first day of class. With that said, you are not expected to be be writing any programs for this lab; for the most part you will just be using Python as a glorified calculator. 1. Getting Started with Python If your primary computer is a laptop, bring it to the lab as it is an excellent opportunity to get started with Python on your machine. Follow the instructions on the Python webpage on the course website. Feel free to ask a consultant for help if you run into problems; that is why they are there. Even if you are just planning to use Python on the ACCEL-lab computers, you still need to learn how to use the Windows Command Prompt before you can get started. Even though it is not officially part of this lab, you should read the tutorial on the Command Prompt on the course web page. Once you understand how to use the Command Prompt, you can get started by typing the word python at the prompt. If you are working in the ACCEL-lab, you should see output that looks something like this: ActivePython 2.7.2.5 (ActiveState Software Inc.) based on Python 2.7.2 (default, Jun 24 2011, 12:22:14) [MSC v. 1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> To use Python, type your expression after the >>>. Python will evaluate the expression and provide the answer. It will then give you another >>> prompt so that you can type in a new expression. There are several shortcuts that can make working with the Python prompt a lot easier. If you press the up-arrow key, you obtain the previous expression that you typed in. Pressing up-arrow repeatedly can scroll through all the expressions that you have typed this session. And 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 moves 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. Lab Instructions Below is a list of expressions. For each expression, you should first compute the expression in your head, without Python. Write down what you think the value is in the second column of the table. If you have no idea, write?. Once you have done that, use Python to compute the same expression. Simply cut 1

2 CS 1110, LAB 1: PYTHON EXPRESSIONS and past the expression from the online version of these instructions into the Interactions pane, and hit the ENTER key. You should write the result in the third column. If the two values are different, you should try to figure out why Python gave the answer that it did. Come up with a reasonable explanation and put it in the final column. You are not really being graded on these labs (see Turning In the Lab (cf. Section 2)), so you should make your best guess at what is happening; your answer will help the instructor and consultants understand how to better aid you. As this is the first lab, it is a little shorter than some of the future labs. With that said, do not waste time! If you don t understand something, ask your lab instructor or a consultant immediately. It is very important that you understand how each expression is evaluated, so if an answer doesn t make sense, ask someone. The lab instructors and consultants are in the lab to help. They will look over your shoulder from time to time and give you advice. Turning in the Lab. Labs are graded on effort, not correctness. When you are finished, you should show your written answers to this lab to your lab instructor, who will record that you did it. You do not actually need to turn in this piece of paper; it is yours to keep. If you do not finish during the lab, finish it within the next few days and show it to your lab instructor next week. Because the lab is graded on effort, you should focus all of your efforts on understanding and not just getting the answers correct. The primary purpose of thes labs is for you to have a hands-on session during which the consultants and instructors can help you out. 3.1. int s. 3. Lab Problems Reason for 2 * 3 2 ** 3 5 + 2 * 5 (5 + 2) * 5 4-3 - 3 4 - (3-3) -4 - -4 - -4 6 / 2 6 / 4

CS 1110, LAB 1: PYTHON EXPRESSIONS 3 Reason for 7 % 2 6 % 3-8 % 3 2 ** 2 ** 0 (2 ** 2) ** 0 3.2. float s. Reason for 5.0 + 2.0 9.0 * 0.5 9.0 ** 0.5 (5 + 2.1) * 5 4.0-3 - 3 4.0 - (3-3) 6.0 / 2 6.0 / 4 6.0 % 3-6.0 % 4 6.2 % 4

4 CS 1110, LAB 1: PYTHON EXPRESSIONS 3.3. Casting and Typing. Reason for float(4) int(4) int(5.3) float(int(5.3)) int(-5.3) float(7) / 4 7 / float(4) float(7 / 4) 7 / 4.0 type(4) type(4.0) type(7 / 4.0) 3.4. boolean s. Reason for 3 < 5 3 < 5 and 5 < 3 True True and False True and True

CS 1110, LAB 1: PYTHON EXPRESSIONS 5 Reason for False True or False True or True not True not False not not False not False and True not False or True not (False or True) True and False and True True or False or True True or (False and True) True or False and True True and (True or False) True and True or False False and (5 / 0 == 1) (5 / 0 == 1) and False For the two expressions in the table above, answer the following question: why does the last expression in the table not work but the one above it does?

6 CS 1110, LAB 1: PYTHON EXPRESSIONS 3.5. String s. In the expressions below, pay close attention to the types of quotation marks being used. We use three different types of quotation marks: ' (single quote), " (double quote), and ` (backquote, reached by hitting shift on the key). In particular, we use the backquote in the last three expressions below. Reason for "Truth " + "is " + "best" "Truth" + "is" + "best" "Truth " + ("is " + "best") "Truth " + 'is ' + "best" ' "Truth" ' " 'Truth' " " "Truth" " 4 / 2 + "" "" + 4 / 2 "" + '4 / 2' "" + `4 / 2` `Truth` ` "Truth" ` Given the results in the table above, answer the following question: what is the difference between the three different types of quotes?

CS 1110, LAB 1: PYTHON EXPRESSIONS 7 3.6. Variables and Assignment Statements. Up until now, you have only worked with expressions. In the table below, we have included assignment statements. It is important that you know the difference between an expression and a statement. An assignment statement like b = 3 < 5; is a command to do something; it evaluates the expression 3 < 5 and stores its value in variable b. Because it is not an expression, Python will not actually output a result when you type it in. It will just perform the command silently. As with the previous part of this lab, you should complete the table below. However, you must enter the expressions or statements in the table below in exactly the order that they are given. Otherwise, you may get different results from everyone else. If the table row is a statement, Python will not return a value, so enter None for the value. We have already done this for one of the entries below. Statement or Reason for i i = 2 None i j = 1 j = j + 9 j k = 5; j + k w = "Hello" i + w