CPTS 111, Fall 2011, Sections 6&7 Exam 3 Review

Size: px
Start display at page:

Download "CPTS 111, Fall 2011, Sections 6&7 Exam 3 Review"

Transcription

1 CPTS 111, Fall 2011, Sections 6&7 Exam 3 Review File processing Files are opened with the open() command. We can open files for reading or writing. The open() command takes two arguments, the file name (string) and the file opening mode (string). Mode is "w" for writing or "r" for reading. The open() command returns a file object. You can invoke the following methods on a file object: o read() -- reads the entire file as a string. o readline() -- reads one line from the file. o readlines() -- reads all the lines in the file and stores them as a list. o close() -- closes the file. o write() -- writes the given string argument to the file. Example file opening scenarios: file = open("input.txt", "r") filename = input("enter file name: ") file = open(filename, "r") Example file reading scenarios: linelist = file.readlines() for line in linelist: # do something with each line in the file filestring = file.read() for ch in filestring: # do something with each character in the file for line in file: # do something with each line in the file

2 Example file writing scenarios: # Writes the given list as a column to the file with the given name def writecolumn(l, filename): file = open(filename, "w") for el in l: file.write(str(el) + '\n') file.close() phrase = input("enter a phrase: ") file = open("input.txt", "w") file.write(phrase) file.close() NOTE: rstrip(), lstrip(), strip() may come handy in file processing! Aliasing Refers to the concept of having two or more variables pointing to the same mutable object. Only mutable object type we ve learned so far is list. All the other types were immutable; i.e strings, integers, floats, tuples are immutable. Important questions to ask are at what conditions o you re creating an alias? o you re not creating an alias? o you re breaking an alias bond? x = 3 y = x x = x + 2 # y is NOT an alias of x # changing x's value won't affect y's value #OUTPUT: 5 3 x = 'hi' y = x x = x + 'jack' # y is NOT an alias of x # changing x's value won't affect y's value #OUTPUT: hijack hi y = x x[0] = 2 # y is an alias of x # change on x that will affect y too #OUTPUT: [2] [2]

3 y = x # y is an alias of x x.append(2) # change on x that will affect y too #OUTPUT: [3, 2] [3, 2] x = [5, 3] y = x x.sort() # y is an alias of x # change on x that will affect y too #OUTPUT: [3, 5] [3, 5] y = x # y is an alias of x x = [3, 4] # x is assigned to another list, y is no longer an alias #OUTPUT: [3, 4] [3] y = x # y is an alias of x x = x + [2] # x is assigned to another list, y is no longer an alias #OUTPUT: [3, 2] [3] y = x[:] x[0] = 2 # y is NOT an alias of x # changing x's value won't affect y's value #OUTPUT: [2] [3] Functions - revisited Function definition is of the form: def <name>(<formal parameters>): <body of function> To call or invoke a function, we write: <name>(<actual parameters>)

4 When you make a function call, essentially what happens is that prior to the body of the function being executed, this statement is executed: <formal parameters> = <actual parameters> Functions' local scopes are invisible from the global scope, but a function can "see" a global variable if it doesn't create any variables of that particular name. def f(): return x # f() can see global variable x x = 5 print(f()) #OUTPUT: 5 def f(): x = 4 return x # f() creates a local variable named x x = 5 print(f(), x) #OUTPUT: 4 5 def f(): x[0] = 4 return x x = [5, 1] print(f(), x) # f() can see global variable x, and change it! # x is a mutable object #OUTPUT: [4, 1] [4, 1] If one passes a mutable object to a function as an argument, alias creating takes place. Practically, a function can change its argument s value if it is a mutable object. def f(a, b): a[0] = 4 b = b * 3 return a + b

5 x = [5, 1] y = [2] print(f(x, y), x, y) #OUTPUT: [4, 1, 2, 2, 2] [4, 1] [2] Conditional statements/if statements if-statement syntax: if <condition>: <body> Body of an if-statement is only executed if the <condition> is True. if-else statements have the following form: if <condition>: <body1> else: <body2> In an if-else statement, if the <condition> is True, then <body1> is executed; if the <condition> is False, then <body2> is executed. elif-else statements have the following form: if <condition1>: <body1> elif <condition2>: <body2> elif <condition3>: <body3>.. else: <bodyn> In an elif-else statement, only one <body> will be executed: the first one that has its <condition> True. If none of the <conditions> are True, then else <body> will be executed (if present). The else part is optional. When writing conditional statements relational operators and Boolean operators are often used.

6 Relational operators Symbol Meaning < less than <= less than or equal to == equal to > greater than >= greater than or equal to!= not equal to Boolean operators Usage True when <expr1> and <expr2> expr1 and expr2 evaluates to True <expr1> or <expr2> expr1 or expr2 evaluates to True not <expr> Expr evaluates to False Precedence rules that applies to relational and boolean operators: o Arithmetic operators has higher precedence over relational operators (meaning arithmetic operators gets evaluated before relational operators) o Relational operators has higher precedence over boolean operators o Among each other, relational operators have the same precedence. o Order of precedence among boolean operators (from higher to lower): not, and, or (not has the highest precedence) o If at same precedence, order of execution is from left to right Python will allow other values when it is expecting a conditional expression. Python considers some things to be False and others to be True. False things: o False (Boolean literal) o None o any numeric value of zero: 0, 0.0, 0j o any empty object True things: everything else! break statements When executed, break statement terminates the enclosing loop. Break statement only breaks the immediate enclosing loop, not any other loop that may be enclosing that loop. Like return statement, any statement that is placed after a break statement (at the same indentation level) won t get executed. Following example demonstrates this:

7 count = 0 for i in range(3): for j in range(3): count = count + 1 print(i+j, end = " ") if(count > 2): break #OUTPUT: count = 0 is_broken = False for i in range(3): for j in range(3): count = count + 1 print(i+j, end = " ") if(count > 2): is_broken = True break if is_broken: break #OUTPUT: while loops -- indefinite loops while-loop syntax: while <condition>: <body> As long as the <condition> is True, <body> of the while-loop is executed. Check out the following simple loop examples, one using for-statement and one using while statement to accomplish the same task: for i in range (5): print(i*i, end = " ") i = 0 while i < 5: print(i*i, end = " ") i = i + 1

8 i = 0 while True: print(i*i, end = " ") i = i + 1 if(i >= 5): break Exercises to work on 1. Write a function called get_names(). This function takes no arguments. When called it prompts the user for a name and places the name in a list. This continues until the user hits enter without entering a name when prompted (input taken would be the empty string). get_names() returns the list of names that the user entered. The following demonstrates the proper behavior of this function. >>> get_names() Enter value: bella Enter value: ben Enter value: [ bella, ben ] >>> 2. Write a function called where_is()that takes a list of names and a query name as input and returns the index where the name appears in the list. This function should return None if the query name is not in the list. The following demonstrates the proper behavior of this function. >>> where_is ([ bella, ben ], ben ) 1 >>> where_is ([ bella, ben ], tim ) >>> 3. Write a function called report().this function takes no arguments. When called it prompts the user for a number until the user enters without a number less than zero. This function returns maximum, minimum and the average of the given numbers. >>> report() Enter value: 12 Enter value: 28 Enter value: 50 Enter value: (50, 12, 30) >>>

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Key Differences Between Python and Java

Key Differences Between Python and Java Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

More information

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review. 1 Python basics. References. CS 234 Naomi Nishimura Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

More information

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

CS 115 Lecture 8. Selection: the if statement. Neil Moore CS 115 Lecture 8 Selection: the if statement Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 24 September 2015 Selection Sometime we want to execute

More information

Programming to Python

Programming to Python Programming to Python Sept., 5 th Slides by M. Stepp, M. Goldstein, M. DiRamio, and S. Shah Compiling and interpreting Many languages require you to compile (translate) your program into a form that the

More information

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

More information

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Simple Data Types There are a number of data types that are considered primitive in that they contain only a single value. These data

More information

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING GE8151 - PROBLEM SOVING AND PYTHON PROGRAMMING Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING 1) Define Computer 2) Define algorithm 3) What are the two phases in algorithmic problem solving? 4) Why

More information

Loop structures and booleans

Loop structures and booleans Loop structures and booleans Michael Mandel Lecture 7 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture07final.ipynb

More information

cs1114 REVIEW of details test closed laptop period

cs1114 REVIEW of details test closed laptop period python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any

More information

https://lambda.mines.edu Why study Python in Principles of Programming Languages? Multi-paradigm Object-oriented Functional Procedural Dynamically typed Relatively simple with little feature multiplicity

More information

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Python I. Some material adapted from Upenn cmpe391 slides and other sources Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information

Flow Control: Branches and loops

Flow Control: Branches and loops Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

Begin to code with Python Obtaining MTA qualification expanded notes

Begin to code with Python Obtaining MTA qualification expanded notes Begin to code with Python Obtaining MTA qualification expanded notes The Microsoft Certified Professional program lets you obtain recognition for your skills. Passing the exam 98-381, "Introduction to

More information

Control Structures 1 / 17

Control Structures 1 / 17 Control Structures 1 / 17 Structured Programming Any algorithm can be expressed by: Sequence - one statement after another Selection - conditional execution (not conditional jumping) Repetition - loops

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

Fall 08, Sherri Goings, Exam #1 (10/2), form 1 B

Fall 08, Sherri Goings, Exam #1 (10/2), form 1 B Fall 08, Sherri Goings, Exam #1 (10/2), form 1 B Last name (printed): First name (printed): Directions: a) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. b) You have 80 minutes to complete

More information

Spring 2017 CS 1110/1111 Exam 2

Spring 2017 CS 1110/1111 Exam 2 Spring 2017 CS 1110/1111 Exam 2 Bubble in your computing ID in the footer of this page. We use an optical scanner to read it, so fill in the bubbles darkly. If you have a shorter ID, leave some rows blank.

More information

18.1. CS 102 Unit 18. Python. Mark Redekopp

18.1. CS 102 Unit 18. Python. Mark Redekopp 18.1 CS 102 Unit 18 Python Mark Redekopp 18.2 Credits Many of the examples below are taken from the online Python tutorial at: http://docs.python.org/tutorial/introduction.html 18.3 Python in Context Two

More information

Chapter 4: Making Decisions

Chapter 4: Making Decisions Chapter 4: Making Decisions 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than or equal to

More information

Session 1: Introduction to Python from the Matlab perspective. October 9th, 2017 Sandra Diaz

Session 1: Introduction to Python from the Matlab perspective. October 9th, 2017 Sandra Diaz Session 1: Introduction to Python from the Matlab perspective October 9th, 2017 Sandra Diaz Working with examples in this course Git repository Work: Exercises we will be interactively working on Slides

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7

Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7 Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7 Program Structure # Print "hello world" to stdout. print 'hello, world' # Print "hello world" to stdout. def f(): print

More information

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1 Review Midterm Exam 1 Review Midterm Exam 1 Exam on Monday, October 7 Data Types and Variables = Data Types and Variables Basic Data Types Integers Floating Point Numbers Strings Data Types and Variables

More information

Python Programming: An Introduction To Computer Science

Python Programming: An Introduction To Computer Science Python Programming: An Introduction To Computer Science Chapter 8 Loop Structures and Booleans Python Programming, 3/e 1 Objectives To understand the concepts of definite and indefinite loops as they are

More information

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1 What to add next time you are updating these slides Update slides to have more animation in the bullet lists Verify that each slide has stand alone speaker notes Page 1 Python 3 Running The Python Interpreter

More information

Chapter 4: Making Decisions

Chapter 4: Making Decisions Chapter 4: Making Decisions CSE 142 - Computer Programming I 1 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >=

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

Visualize ComplexCities

Visualize ComplexCities Introduction to Python Chair of Information Architecture ETH Zürich February 22, 2013 First Steps Python Basics Conditionals Statements Loops User Input Functions Programming? Programming is the interaction

More information

1 Truth. 2 Conditional Statements. Expressions That Can Evaluate to Boolean Values. Williams College Lecture 4 Brent Heeringa, Bill Jannen

1 Truth. 2 Conditional Statements. Expressions That Can Evaluate to Boolean Values. Williams College Lecture 4 Brent Heeringa, Bill Jannen 1 Truth Last lecture we learned about the int, float, and string types. Another very important object type in Python is the boolean type. The two reserved keywords True and False are values with type boolean.

More information

Programming with Python

Programming with Python Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2

More information

APT Session 2: Python

APT Session 2: Python APT Session 2: Python Laurence Tratt Software Development Team 2017-10-20 1 / 17 http://soft-dev.org/ What to expect from this session: Python 1 What is Python? 2 Basic Python functionality. 2 / 17 http://soft-dev.org/

More information

INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0

INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0 INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0 OCTOBER 2014 Python Selection and Conditionals 1 SELECTION AND CONDITIONALS WHAT YOU MIGHT KNOW ALREADY You will probably be familiar

More information

Overview of List Syntax

Overview of List Syntax Lists and Sequences Overview of List Syntax x = [0, 0, 0, 0] Create list of length 4 with all zeroes x 4300112 x.append(2) 3 in x x[2] = 5 x[0] = 4 k = 3 Append 2 to end of list x (now length 5) Evaluates

More information

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2015 Chapter 8 Part 1 The Department of Computer Science Chapter 8 Loop Structures and Booleans 2 Objectives To understand the concepts

More information

Chapter 6: Files and Exceptions. COSC 1436, Spring 2017 Hong Sun 3/6/2017

Chapter 6: Files and Exceptions. COSC 1436, Spring 2017 Hong Sun 3/6/2017 Chapter 6: Files and Exceptions COSC 1436, Spring 2017 Hong Sun 3/6/2017 Function Review: A major purpose of functions is to group code that gets executed multiple times. Without a function defined, you

More information

PREPARING FOR PRELIM 1

PREPARING FOR PRELIM 1 PREPARING FOR PRELIM 1 CS 1110: FALL 2012 This handout explains what you have to know for the first prelim. There will be a review session with detailed examples to help you study. To prepare for the prelim,

More information

Module 04: Lists. Topics: Lists and their methods Mutating lists Abstract list functions Readings: ThinkP 8, 10. CS116 Fall : Lists

Module 04: Lists. Topics: Lists and their methods Mutating lists Abstract list functions Readings: ThinkP 8, 10. CS116 Fall : Lists Module 04: Lists Topics: Lists and their methods Mutating lists Abstract list functions Readings: ThinkP 8, 10 1 Consider the string method split >>> name = "Harry James Potter" >>> name.split() ['Harry',

More information

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

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. Plan for the rest of the semester: Programming We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. We saw earlier that computers

More information

ENGR 102 Engineering Lab I - Computation

ENGR 102 Engineering Lab I - Computation ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;

More information

Flow Control. So Far: Writing simple statements that get executed one after another.

Flow Control. So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow control allows the programmer

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

File Input/Output. Learning Outcomes 10/8/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01. Discussion Sections 02-08, 16, 17

File Input/Output. Learning Outcomes 10/8/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01. Discussion Sections 02-08, 16, 17 CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 1 Discussion Sections 02-08, 16, 17 Adapted from slides by Sue Evans et al. 2 Learning Outcomes Become familiar with input and output (I/O) from

More information

Computer Science 217

Computer Science 217 Computer Science 17 Midterm Exam March 5, 014 Exam Number 1 First Name: Last Name: ID: Class Time (Circle One): 1:00pm :00pm Instructions: Neatly print your names and ID number in the spaces provided above.

More information

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems CSSE 120 Introduction to Software Development Exam 1 Format, Concepts, What you should be able to do, and Sample Problems Page 1 of 6 Format: The exam will have two sections: Part 1: Paper-and-Pencil o

More information

Compound Data Types 1

Compound Data Types 1 Compound Data Types 1 Chapters 8, 10 Prof. Mauro Gaspari: mauro.gaspari@unibo.it Compound Data Types Strings are compound data types: they are sequences of characters. Int and float are scalar data types:

More information

Comp Exam 1 Overview.

Comp Exam 1 Overview. Comp 170-400 Exam 1 Overview. Resources During the Exam The exam will be closed book, no calculators or computers, except as a word processor. In particular no Python interpreter running in a browser or

More information

Python for Non-programmers

Python for Non-programmers Python for Non-programmers A Gentle Introduction 2 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013

More information

bash Execution Control COMP2101 Winter 2019

bash Execution Control COMP2101 Winter 2019 bash Execution Control COMP2101 Winter 2019 Bash Execution Control Scripts commonly can evaluate situations and make simple decisions about actions to take Simple evaluations and actions can be accomplished

More information

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. CSE 231 F 13 Exam #1 Last name (printed): First name (printed): Form 1 X Directions: a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. b. This exam booklet contains 25 questions, each

More information

Introduction to Python

Introduction to Python May 25, 2010 Basic Operators Logicals Types Tuples, Lists, & Dictionaries and or Building Functions Labs From a non-lab computer visit: http://www.csuglab.cornell.edu/userinfo Running your own python setup,

More information

CPSC 3740 Programming Languages University of Lethbridge. Control Structures

CPSC 3740 Programming Languages University of Lethbridge. Control Structures Control Structures A control structure is a control statement and the collection of statements whose execution it controls. Common controls: selection iteration branching Control Structures 1 15 Howard

More information

Lecture. Loops && Booleans. Richard E Sarkis CSC 161: The Art of Programming

Lecture. Loops && Booleans. Richard E Sarkis CSC 161: The Art of Programming Lecture Loops && Booleans Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda (In-)definite loops (for/while) Patterns: interactive loop and sentinel loop Solve problems using (possibly

More information

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Python Basics. Lecture and Lab 5 Day Course. Python Basics Python Basics Lecture and Lab 5 Day Course Course Overview Python, is an interpreted, object-oriented, high-level language that can get work done in a hurry. A tool that can improve all professionals ability

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

C++ for Python Programmers

C++ for Python Programmers C++ for Python Programmers Adapted from a document by Rich Enbody & Bill Punch of Michigan State University Purpose of this document This document is a brief introduction to C++ for Python programmers

More information

LECTURE 04 MAKING DECISIONS

LECTURE 04 MAKING DECISIONS PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 04 MAKING DECISIONS

More information

The current topic: Python. Announcements. Python. Python

The current topic: Python. Announcements. Python. Python The current topic: Python Announcements! Introduction! reasons for studying languages! language classifications! simple syntax specification Object-oriented programming: Python Types and values Syntax

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

Here n is a variable name. The value of that variable is 176.

Here n is a variable name. The value of that variable is 176. UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence

More information

PIC 16, Fall Variables, Dynamically-typed, Mutable, Immutable, Functions. Michael Andrews. October 1, Department of Mathematics UCLA

PIC 16, Fall Variables, Dynamically-typed, Mutable, Immutable, Functions. Michael Andrews. October 1, Department of Mathematics UCLA PIC 16, Fall 2018 Variables, Dynamically-typed, Mutable, Immutable, Functions Michael Andrews Department of Mathematics UCLA October 1, 2018 Office hours reminder M 1:30-2:45pm (Michael) T 1-2pm (Sam),

More information

Part III Appendices 165

Part III Appendices 165 Part III Appendices 165 Appendix A Technical Instructions Learning Outcomes This material will help you learn how to use the software you need to do your work in this course. You won t be tested on it.

More information

Programming in Python 3

Programming in Python 3 Programming in Python 3 Programming transforms your computer from a home appliance to a power tool Al Sweigart, The invent with Python Blog Programming Introduction Write programs that solve a problem

More information

Getting Started with Python

Getting Started with Python Fundamentals of Programming (Python) Getting Started with Python Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science

More information

Outline. Collections Arrays vs. Lists Functions using Arrays/Lists Higher order functions using Arrays/Lists

Outline. Collections Arrays vs. Lists Functions using Arrays/Lists Higher order functions using Arrays/Lists Arrays and Lists Outline Collections Arrays vs. Lists Functions using Arrays/Lists Higher order functions using Arrays/Lists Collections We've seen tuples to store multiple objects together, but the tuple

More information

Java+- Language Reference Manual

Java+- Language Reference Manual Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Arithmetic Expressions in C

Arithmetic Expressions in C Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic

More information

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015 CS 115 Exam 1, Fall 2015 Thu. 09/24/2015 Name: Section: Rules and Hints You may use one handwritten 8.5 11 cheat sheet (front and back). This is the only additional resource you may consult during this

More information

Name Feb. 14, Closed Book/Closed Notes No electronic devices of any kind! 3. Do not look at anyone else s exam or let anyone else look at yours!

Name Feb. 14, Closed Book/Closed Notes No electronic devices of any kind! 3. Do not look at anyone else s exam or let anyone else look at yours! Name Feb. 14, 2018 CPTS 111 EXAM #1 Closed Book/Closed Notes No electronic devices of any kind! Directions: 1. Breathe in deeply, exhale slowly, and relax. 2. No hats or sunglasses may be worn during the

More information

Lecture no

Lecture no Advanced Algorithms and Computational Models (module A) Lecture no. 3 29-09-2014 Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 28 Expressions, Operators and Precedence Sequence Operators The following

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala Loops and Conditionals HORT 59000 Lecture 11 Instructor: Kranthi Varala Relational Operators These operators compare the value of two expressions and returns a Boolean value. Beware of comparing across

More information

Lecture #12: Mutable Data. map rlist Illustrated (III) map rlist Illustrated. Using Mutability For Construction: map rlist Revisited

Lecture #12: Mutable Data. map rlist Illustrated (III) map rlist Illustrated. Using Mutability For Construction: map rlist Revisited Lecture #12: Mutable Data Using Mutability For Construction: map rlist Revisited Even if we never change a data structure once it is constructed, mutation may be useful during its construction. Example:

More information

Control, Quick Overview. Selection. Selection 7/6/2017. Chapter 2. Control

Control, Quick Overview. Selection. Selection 7/6/2017. Chapter 2. Control Chapter 2 Control, Quick Overview Control Selection Selection Selection is how programs make choices, and it is the process of making choices that provides a lot of the power of computing 1 Python if statement

More information

CS 1301 Final Exam Review Guide

CS 1301 Final Exam Review Guide CS 1301 Final Exam Review Guide A. Programming and Algorithm 1. Binary, Octal-decimal, Decimal, and Hexadecimal conversion Definition Binary (base 2): 10011 = 1*2 4 + 0*2 3 + 0*2 2 + 1*2 1 + 1*2 0 Octal-decimal

More information

EE 355 Unit 17. Python. Mark Redekopp

EE 355 Unit 17. Python. Mark Redekopp 1 EE 355 Unit 17 Python Mark Redekopp 2 Credits Many of the examples below are taken from the online Python tutorial at: http://docs.python.org/tutorial/introduction.html 3 Python in Context Interpreted,

More information

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s Intro to Python Python Getting increasingly more common Designed to have intuitive and lightweight syntax In this class, we will be using Python 3.x Python 2.x is still very popular, and the differences

More information

Data Abstraction. UW CSE 160 Spring 2015

Data Abstraction. UW CSE 160 Spring 2015 Data Abstraction UW CSE 160 Spring 2015 1 What is a program? What is a program? A sequence of instructions to achieve some particular purpose What is a library? A collection of functions that are helpful

More information

STSCI Python Introduction. Class URL

STSCI Python Introduction. Class URL STSCI Python Introduction Class 2 Jim Hare Class URL www.pst.stsci.edu/~hare Each Class Presentation Homework suggestions Example files to download Links to sites by each class and in general I will try

More information

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz Senet Language Reference Manual 26 th October 2015 Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz 1. Overview Past projects for Programming Languages and Translators have

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Lecture 02 Making Decisions: Conditional Execution

Lecture 02 Making Decisions: Conditional Execution Lecture 02 Making Decisions: Conditional Execution 1 Flow of Control Flow of control = order in which statements are executed By default, a program's statements are executed sequentially, from top to bottom.

More information

THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists

THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September 2016 COMP1730 / COMP6730 Programming for Scientists Study Period: 15 minutes Time Allowed: 2 hours Permitted Materials: One A4 page

More information

The Practice of Computing Using PYTHON

The Practice of Computing Using PYTHON The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 6 Lists and Tuples 1 Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Data Structures 2 Data Structures

More information

Announcements COMP 141. Writing to a File. Reading From a File 10/18/2017. Reading/Writing from/to Files

Announcements COMP 141. Writing to a File. Reading From a File 10/18/2017. Reading/Writing from/to Files Announcements COMP 141 Reading/Writing from/to Files Reminders Program 5 due Thurs., October 19 th by 11:55pm Solutions to selected problems from Friday s lab are in my Box.com directory (LoopLab.py) Programming

More information

CS1 Lecture 3 Jan. 22, 2018

CS1 Lecture 3 Jan. 22, 2018 CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow

More information

File input and output if-then-else. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

File input and output if-then-else. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas File input and output if-then-else Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Opening files The open() command returns a file object: = open(,

More information

Decision Making in C

Decision Making in C Decision Making in C Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed

More information

SECTION II: LANGUAGE BASICS

SECTION II: LANGUAGE BASICS Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

More information

Variable and Data Type I

Variable and Data Type I The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved

More information

File input and output and conditionals. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

File input and output and conditionals. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas File input and output and conditionals Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Opening files The built-in open() function returns a file object:

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Compound Data Types 2

Compound Data Types 2 Compound Data Types 2 Chapters 10, 11, 12 Prof. Mauro Gaspari: gaspari@cs.unibo.it Objects and Values We know that a and b both refer to a string, but we don t know whether they refer to the same string.

More information

VLC : Language Reference Manual

VLC : Language Reference Manual VLC : Language Reference Manual Table Of Contents 1. Introduction 2. Types and Declarations 2a. Primitives 2b. Non-primitives - Strings - Arrays 3. Lexical conventions 3a. Whitespace 3b. Comments 3c. Identifiers

More information

Introduction to Python

Introduction to Python Introduction to Python EECS 4415 Big Data Systems Tilemachos Pechlivanoglou tipech@eecs.yorku.ca 2 Background Why Python? "Scripting language" Very easy to learn Interactive front-end for C/C++ code Object-oriented

More information

Fundamentals of Programming (Python) Getting Started with Programming

Fundamentals of Programming (Python) Getting Started with Programming Fundamentals of Programming (Python) Getting Started with Programming Ali Taheri Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science

More information

(Python) Chapter 3: Repetition

(Python) Chapter 3: Repetition (Python) Chapter 3: Repetition 3.1 while loop Motivation Using our current set of tools, repeating a simple statement many times is tedious. The only item we can currently repeat easily is printing the

More information