CS 112: Intro to Comp Prog

Size: px
Start display at page:

Download "CS 112: Intro to Comp Prog"

Transcription

1 CS 112: Intro to Comp Prog Importing modules Branching Loops Program Planning Arithmetic Program Lab Assignment #2 Upcoming

2 Assignment #1 Solution CODE: # lab1.py # Student Name: John Noname # Assignment: Lab #1 # Submission Date: 02/09/2009 # Honor Code Statement: I received no assistance on this assignment that # violates the guidelines as set forth by the instructor # and the class syllabus. # References: Python Programming for the absolute beginner (book) # Comments: Our first assignment # Defining the main function def main(): #printing name and major print ''' Name: John Noname Major: Electrical Engineering ''' #prompting user to hit enter to exit the program raw_input("press <Enter> to exit...") print "Good bye" #Calling the main function main()

3 Assignment #1 Solution Q1. What steps do you take to create a program using IDLE? (Include creating a new file, saving it, and executing it) Ans. -After opening idle, click on file, select "New Window". -Write your code in the opened script window -To save the file click on file again and select "save as" *select the directory you want to store your file in using the pop-up dialog window. *name the file followed by a.py extension. -The file can be executed clicking in the menu "Run Module" (F5). Q2. What steps do you take to create a program (using a text editor) in your operating system? (Include creating a new file, saving it, and executing it) Ans. -Open text editor (eg. notepad) -Click on file, select "new" -To save the file click on file again and select "save as" *select the directory you want to store your file in. *name the file followed by a.py extension. -To run the file, open command prompt *type "cd" with the appropriate directory to get to the location of the script file (.py), use "dir" or "ls" (depending on your OS) to verify the file is in that directory *Once you have found the file, type "python file_name" where file_name is the name of the file you saved Q3. Is it possible to create a program using the method from Q1 and execute it using the method from Q2? Ans. Yes

4 Lecture Topics Theory...why have these constructs in programming? Modules Can separate code into separate files grouping similar functions (math is the best example). Good for organization, usability, and distribution Branching Programs no longer have to run sequentially, i.e. always behaves the same way. Now programs can be dynamic based on user's input. Looping Allows for arbitrary code to be repeated...before code would have to be copied and pasted; thus would have to be for a set number of times.

5 Importing modules module: a file that contains external code that is related There are many different modules that have been created and are available to be used by your code. (Tkinter, math, os) Importing loads the code and allows your program to access specific functions Example module: random Function: randrange(<bound>) #gets a number between 0 and (<bound> - 1) # Will randomly display a number in the range 0 to 4 import random print random.randrange(5)

6 if-structure if <condition>: <statements to perform when condition is true> <tabbing signifies which statements are contained> <within the if-block> <code not tabbed is always run> Example: num = int(raw_input("enter a number")) if (num % 2) == 0: print str(num)+" is even!" print "It is a good number"

7 if-else structure if <condition>: else: <statements to perform when condition is true> <...> <statements to perform when condition is false> <...> <code not tabbed is always run> Example: num = int(raw_input("enter a number")) if (num % 2) == 0: print str(num)+" is even!" else: print str(num)+" is odd!"

8 Conditions Conditions are expressions that evaluate to True or False Comparison Operators are used to create these expressions == equal to!= not equal to > greater than >= greater than or equal to < less than <= less than or equal to Examples: (10 / 2) == 5 True HELLO == hello False

9 Conditions Values in variables can also be directly evaluated to True or False Numeric: 0 == False, everything else is true String: == False, everything else is true Condition expressions can be combined/modified using Logical Operators not #negate the boolean value (false -> true) and #both sides of operator must be true or #at least one side of operator must be true There exists several parallels with if-statements and logical operators, and many times, solutions can be found through a variety of means.

10 Conditions if (num % 2)!= 0: print str(num)+" is odd! #Equivalent to: if not ((num % 2) == 0): print str(num)+" is odd!" if (num % 2) == 0 and (num % 3) == 0: print str(num)+" is divisible by 6!" #Equivalent to: if (num % 2) == 0: if (num % 3) == 0: print str(num)+" is divisible by 6!"

11 Conditions if userinput == "yes" or userinput == "YES": print "I am glad you feel that way" #Equivalent to: if userinput == "yes": print "I am glad you feel that way" if userinput == "YES": print "I am glad you feel that way"

12 if-elif-...-else structure if <condition1>: <statements to perform when condition1 is true> <...> elif <condition2>: <statements to perform when condition2 is true> <...> <...many elif statements may follow> else: <statements to perform when all above conditions> <are false> <...> <code not tabbed is always run>

13 if-elif-...-else structure Example: print "1. Print \"Hello\"" print "2. Print \"Good-bye\"" print "3. Print \"Zzzzzz\"" num = int(raw_input("enter your choice")) if num == 1: print "Hello" elif num == 2: print "Good-bye" elif num == 3: print "Zzzzzz" else: print "Not a valid choice"

14 while structure while <condition>: <statements to perform when condition is true> <tabbing signifies which statements are contained> <within the while-block. Once tabbed statements are> <executed program goes back to top to check> <condition again...repeat until false> <code not tabbed is always run, and is where code> <resumes when loop finishes, careful of infinite loops> Example: num = 0 while not num: num = int(raw_input("enter a non-zero number")) print "Hurray you chose: "+ str(num)

15 break continue Sometimes you may want to alter the way your loop runs from inside the loop rather than waiting for a single iteration of the loop to finish. We can do this with two commands: break - this will stop the loop and jump the program to run the code after the loop body (i.e. the tabbed code) continue - this will skip all lines of code inside the loop, jumping the program back to check the condition of the loop

16 Program Planning (Revisit) Write a program that will ask the user for two decimal numbers, then list a set of operations for them to choose (1 sum, 2 difference, 3 product, 4 quotient, 5 Quit). Display the solution to their choice. After the solution is printed redisplay the menu for them to choose another option until they choose 5, if they type any number other than 1-5 display an error message and continue to display the menu again. Terminal is as shown:

17 Identify the Main Steps Entering the two numbers Displaying the menu Entering a choice Branching for choice Repeating Menu

18 Identify the Variables Number 1 - num1 Number 2 - num2 User's Choice - choice Could have decided to have variables for each arithmetic operation, but will do the calculations in-line.

19 Pseudo-code Get user values for the two decimal numbers Create an infinite loop only to be stopped if 5 entered Print menu Get the user's choice of what operation to perform If choice is 1 print num1 + num2 If choice is 2 print num1 - num2 If choice is 3 print num1 * num2 If choice is 4 print num1 / num2 If choice is 5 stop the loop If choice is anything other than 1 5 restart loop ************************************************************** FOR YOU: Take the time to convert the above pseudo-code into python code.

20 Assignment #3 Due next week before lab You need to turn in one file Lab3.py Contains the proper comment header Reads input from the user Constructs the proper date string Gathers info using the webbrowser module Outputs the result as shown in the example output Again make sure to verify that everything was submitted

21 Upcoming Loops, Strings, Tuples, and Number-Base Conversion Finish Lab Assignment #3 and be sure to complete it before next week's lab Read Chapter 4 in the textbook

CS 112: Intro to Comp Prog

CS 112: Intro to Comp Prog CS 112: Intro to Comp Prog Importing modules Branching Loops Program Planning Arithmetic Program Lab Assignment #2 Upcoming Importing modules module: a file that contains external code that is related

More information

CS 112: Intro to Comp Prog

CS 112: Intro to Comp Prog CS 112: Intro to Comp Prog Lecture Review Data Types String Operations Arithmetic Operators Variables In-Class Exercises Lab Assignment #2 Upcoming Lecture Topics Variables * Types Functions Purpose Parameters

More information

CS100: CPADS. Decisions. David Babcock / Don Hake Department of Physical Sciences York College of Pennsylvania

CS100: CPADS. Decisions. David Babcock / Don Hake Department of Physical Sciences York College of Pennsylvania CS100: CPADS Decisions David Babcock / Don Hake Department of Physical Sciences York College of Pennsylvania James Moscola Decisions Just like a human, programs need to make decisions - Should turtle turn

More information

CME 193: Introduction to Scientific Python Lecture 1: Introduction

CME 193: Introduction to Scientific Python Lecture 1: Introduction CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements

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

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15 1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

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

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

CSC116: Introduction to Computing - Java

CSC116: Introduction to Computing - Java CSC116: Introduction to Computing - Java Course Information Introductions Website Syllabus Computers First Java Program Text Editor Helpful Commands Java Download Intro to CSC116 Instructors Course Instructor:

More information

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Scripting Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss What a shell

More information

CSC116: Introduction to Computing - Java

CSC116: Introduction to Computing - Java CSC116: Introduction to Computing - Java Intro to CSC116 Course Information Introductions Website Syllabus Computers First Java Program Text Editor Helpful Commands Java Download Course Instructor: Instructors

More information

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation CPSC 150 Laboratory Manual A Practical Approach to Java, jedit & WebCAT Department of Physics, Computer Science & Engineering Christopher Newport University Lab 1 Introduction to Program Creation Welcome

More information

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++ Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017 Loops! Loops! Loops! Lecture 5 COP 3014 Fall 2017 September 25, 2017 Repetition Statements Repetition statements are called loops, and are used to repeat the same code mulitple times in succession. The

More information

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

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY CS 111X - Fall 2016 - Test 1 1/9 Computing ID: CS 111X - Fall 2016 - Test 1 - KEY KEY KEY KEY KEY KEY KEY Name: Computing ID: On my honor as a student, I have neither given nor received unauthorized assistance

More information

[CHAPTER] 1 INTRODUCTION 1

[CHAPTER] 1 INTRODUCTION 1 FM_TOC C7817 47493 1/28/11 9:29 AM Page iii Table of Contents [CHAPTER] 1 INTRODUCTION 1 1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing...2 1.1.1 Algorithms...2 1.1.2

More information

Programming Fundamentals

Programming Fundamentals Programming Fundamentals Computers are really very dumb machines -- they only do what they are told to do. Most computers perform their operations on a very primitive level. The basic operations of a computer

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

Math 98 - Introduction to MATLAB Programming. Fall Lecture 1

Math 98 - Introduction to MATLAB Programming. Fall Lecture 1 Syllabus Instructor: Chris Policastro Class Website: https://math.berkeley.edu/~cpoli/math98/fall2016.html See website for 1 Class Number 2 Oce hours 3 Textbooks 4 Lecture schedule slides programs Syllabus

More information

Lecture 10. Daily Puzzle

Lecture 10. Daily Puzzle Lecture 10 Daily Puzzle Imagine there is a ditch, 10 feet wide, which is far too wide to jump. Using only eight narrow planks, each no more than 9 feet long, construct a bridge across the ditch. Daily

More information

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

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

Lab 5a Shell Script Lab 4 Using Arithmetic Operators in shell script

Lab 5a Shell Script Lab 4 Using Arithmetic Operators in shell script Lab 5a Shell Script Lab 4 Using Arithmetic Operators in shell script Objective Upon completion of this lab, the student will be able to use arithmetic operators in Linux shell script. Scenario The student

More information

CIS192: Python Programming

CIS192: Python Programming CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms

More information

Lecture 1: Hello, MATLAB!

Lecture 1: Hello, MATLAB! Lecture 1: Hello, MATLAB! Math 98, Spring 2018 Math 98, Spring 2018 Lecture 1: Hello, MATLAB! 1 / 21 Syllabus Instructor: Eric Hallman Class Website: https://math.berkeley.edu/~ehallman/98-fa18/ Login:!cmfmath98

More information

CS 111X - Fall Test 1

CS 111X - Fall Test 1 CS 111X - Fall 2016 - Test 1 1/9 Computing ID: CS 111X - Fall 2016 - Test 1 Name: Computing ID: On my honor as a student, I have neither given nor received unauthorized assistance on this exam. Signature:

More information

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points Files to submit: 1. HW3.py This is a PAIR PROGRAMMING Assignment: Work with your partner! For pair

More information

2. Explain the difference between read(), readline(), and readlines(). Give an example of when you might use each.

2. Explain the difference between read(), readline(), and readlines(). Give an example of when you might use each. CMSC 0 Fall 0 Name Final Review Worksheet This worksheet is NOT guaranteed to cover every topic you might see on the exam. It is provided to you as a courtesy, as additional practice problems to help you

More information

Unit 7: Algorithms and Python CS 101, Fall 2018

Unit 7: Algorithms and Python CS 101, Fall 2018 Unit 7: Algorithms and Python CS 101, Fall 2018 Learning Objectives After completing this unit, you should be able to: Identify whether a sequence of steps is an algorithm in the strict sense. Explain

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

Conditionals & Control Flow

Conditionals & Control Flow CS 1110: Introduction to Computing Using Python Lecture 8 Conditionals & Control Flow [Andersen, Gries, Lee, Marschner, Van Loan, White] Announcements: Assignment 1 Due tonight at 11:59pm. Suggested early

More information

Loops In Python. In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.

Loops In Python. In this section of notes you will learn how to rerun parts of your program without having to duplicate the code. Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code. The Need For Repetition (Loops) Writing out a simple counting program (1

More information

Decisions, Decisions. Testing, testing C H A P T E R 7

Decisions, Decisions. Testing, testing C H A P T E R 7 C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little

More information

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers A Big Step Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Copyright 2006 2009 Stewart Weiss What a shell really does Here is the scoop on shells. A shell is a program

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

Programming for Experimental Research. Flow Control

Programming for Experimental Research. Flow Control Programming for Experimental Research Flow Control FLOW CONTROL In a simple program, the commands are executed one after the other in the order they are typed. Many situations require more sophisticated

More information

CS11001/CS11002 Programming and Data Structures Autumn/Spring Semesters. Introduction

CS11001/CS11002 Programming and Data Structures Autumn/Spring Semesters. Introduction Title page CS11001/CS11002 Programming and Data Structures Autumn/Spring Semesters Introduction Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Last modified: July

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

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

CS 1110, LAB 3: MODULES AND TESTING   First Name: Last Name: NetID: CS 1110, LAB 3: MODULES AND TESTING http://www.cs.cornell.edu/courses/cs11102013fa/labs/lab03.pdf First Name: Last Name: NetID: The purpose of this lab is to help you better understand functions, and to

More information

Conditionals and Recursion. Python Part 4

Conditionals and Recursion. Python Part 4 Conditionals and Recursion Python Part 4 Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print (remainder) 1 Boolean expressions An expression that

More information

CSC116: Introduction to Computing - Java

CSC116: Introduction to Computing - Java CSC116: Introduction to Computing - Java Course Information Introductions Website Syllabus Schedule Computing Environment AFS (Andrew File System) Linux/Unix Commands Helpful Tricks Computers First Java

More information

Project 1. due date Sunday July 8, 2018, 12:00 noon

Project 1. due date Sunday July 8, 2018, 12:00 noon Queens College, CUNY, Department of Computer Science Object-oriented programming in C++ CSCI 211 / 611 Summer 2018 Instructor: Dr. Sateesh Mane c Sateesh R. Mane 2018 Project 1 due date Sunday July 8,

More information

Lab1. Introduction to Python. Lab 4: Selection Statement. Eng. Mai Z. Alyazji

Lab1. Introduction to Python. Lab 4: Selection Statement. Eng. Mai Z. Alyazji Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Introduction to Computers Lab (ENGG 1003) Lab1 Introduction to Python Lab 4: Selection Statement Eng. Mai Z. Alyazji In this

More information

Loops In Python. In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.

Loops In Python. In this section of notes you will learn how to rerun parts of your program without having to duplicate the code. Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code. Application Of Loops In Actual Software Play again? Re-running specific

More information

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

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup Purpose: The purpose of this lab is to setup software that you will be using throughout the term for learning about Python

More information

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version... Contents Note: pay attention to where you are........................................... 1 Note: Plaintext version................................................... 1 Hello World of the Bash shell 2 Accessing

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

Syllabus COSC-051-x - Computer Science I Fall Office Hours: Daily hours will be entered on Course calendar (or by appointment)

Syllabus COSC-051-x - Computer Science I Fall Office Hours: Daily hours will be entered on Course calendar (or by appointment) Syllabus COSC-051-x - Computer Science I Fall 2018 Instructor: Jeremy Bolton, Ph.D. Asst Teaching Professor Department of Computer Science Office: TBD (see Course calendar for office hours) Email: jeremy.bolton@georgetown.edu

More information

Conditional Control Structures. Dr.T.Logeswari

Conditional Control Structures. Dr.T.Logeswari Conditional Control Structures Dr.T.Logeswari TEST COMMAND test expression Or [ expression ] Syntax Ex: a=5; b=10 test $a eq $b ; echo $? [ $a eq $b] ; echo $? 2 Unix Shell Programming - Forouzan 2 TEST

More information

CSE 115. Introduction to Computer Science I

CSE 115. Introduction to Computer Science I CSE 115 Introduction to Computer Science I Progress In UBInfinite? A. Haven't started B. Earned 3 stars in "Calling Functions" C. Earned 3 stars in "Defining Functions" D. Earned 3 stars in "Conditionals"

More information

Lecture 8. Conditionals & Control Flow

Lecture 8. Conditionals & Control Flow Lecture 8 Conditionals & Control Flow Announcements For This Lecture Readings Sections 5.1-5.7 today Chapter 4 for Tuesday Assignment 2 Posted Today Written assignment Do while revising A1 Assignment 1

More information

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6 Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #5 due today Lab #3

More information

The Practice of Computing Using PYTHON. Chapter 2. Control. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

The Practice of Computing Using PYTHON. Chapter 2. Control. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 2 Control 1 Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Control: A Quick Overview 2 Selection

More information

Pattern Maker Lab. 1 Preliminaries. 1.1 Writing a Python program

Pattern Maker Lab. 1 Preliminaries. 1.1 Writing a Python program Pattern Maker Lab Lab Goals: In this lab, you will write a Python program to generate different patterns using ASCII characters. In particular, you will get practice with the following: 1. Printing strings

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables

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

CS1 Lecture 5 Jan. 25, 2019

CS1 Lecture 5 Jan. 25, 2019 CS1 Lecture 5 Jan. 25, 2019 HW1 due Monday, 9:00am. Notes: Do not write all the code at once before starting to test. Take tiny steps. Write a few lines test... add a line or two test... add another line

More information

CS1110 Lab 1 (Jan 27-28, 2015)

CS1110 Lab 1 (Jan 27-28, 2015) 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

More information

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

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this

More information

CS 112: Intro to Comp Prog

CS 112: Intro to Comp Prog CS 112: Intro to Comp Prog Data Types String In-detail Arithmetic Operators Variables Tipper Program Lab Assignment #1 Upcoming Data Types Integer int () (aka Fixed-Point)

More information

CS457/557 Functional Languages

CS457/557 Functional Languages CS457/557 Functional Languages Spring 2018 Lecture 1: Course Introduction Andrew Tolmach Portland State University (with thanks to Mark P. Jones) 1 Goals of this course Introduce the beautiful ideas of

More information

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8 CS 302: INTRODUCTION TO PROGRAMMING Lectures 7&8 Hopefully the Programming Assignment #1 released by tomorrow REVIEW The switch statement is an alternative way of writing what? How do you end a case in

More information

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

CS 1110, LAB 12: SEQUENCE ALGORITHMS   First Name: Last Name: NetID: CS 1110, LAB 12: SEQUENCE ALGORITHMS http://www.cs.cornell.edu/courses/cs1110/2014fa/labs/lab12.pdf First Name: Last Name: NetID: This last lab is extremely important. It helps you understand how to construct

More information

1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman

1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman 1. BASICS OF PYTHON JHU Physics & Astronomy Python Workshop 2017 Lecturer: Mubdi Rahman HOW IS THIS WORKSHOP GOING TO WORK? We will be going over all the basics you need to get started and get productive

More information

CS11002 Programming and Data Structures Spring Introduction

CS11002 Programming and Data Structures Spring Introduction Title page CS11002 Programming and Data Structures Spring 2008 Goutam Biswas Abhijit Das Dipankar Sarkar Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Jan 04, 2008

More information

Week - 01 Lecture - 04 Downloading and installing Python

Week - 01 Lecture - 04 Downloading and installing Python Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and

More information

Jython. secondary. memory

Jython. secondary. memory 2 Jython secondary memory Jython processor Jython (main) memory 3 Jython secondary memory Jython processor foo: if Jython a

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

Lecture 1. Types, Expressions, & Variables

Lecture 1. Types, Expressions, & Variables Lecture 1 Types, Expressions, & Variables About Your Instructor Director: GDIAC Game Design Initiative at Cornell Teach game design (and CS 1110 in fall) 8/29/13 Overview, Types & Expressions 2 Helping

More information

SCRATCH MODULE 3: NUMBER CONVERSIONS

SCRATCH MODULE 3: NUMBER CONVERSIONS SCRATCH MODULE 3: NUMBER CONVERSIONS INTRODUCTION The purpose of this module is to experiment with user interactions, error checking input, and number conversion algorithms in Scratch. We will be exploring

More information

CIS192 Python Programming. Robert Rand. August 27, 2015

CIS192 Python Programming. Robert Rand. August 27, 2015 CIS192 Python Programming Introduction Robert Rand University of Pennsylvania August 27, 2015 Robert Rand (University of Pennsylvania) CIS 192 August 27, 2015 1 / 30 Outline 1 Logistics Grading Office

More information

Comp 151. Control structures.

Comp 151. Control structures. Comp 151 Control structures. admin For these slides read chapter 7 Yes out of order. Simple Decisions So far, we ve viewed programs as sequences of instructions that are followed one after the other. While

More information

CMSC 201 Spring 2018 Lab 01 Hello World

CMSC 201 Spring 2018 Lab 01 Hello World CMSC 201 Spring 2018 Lab 01 Hello World Assignment: Lab 01 Hello World Due Date: Sunday, February 4th by 8:59:59 PM Value: 10 points At UMBC, the GL system is designed to grant students the privileges

More information

Lab 4: Bash Scripting

Lab 4: Bash Scripting Lab 4: Bash Scripting February 20, 2018 Introduction This lab will give you some experience writing bash scripts. You will need to sign in to https://git-classes. mst.edu and git clone the repository for

More information

LECTURE 5 Control Structures Part 2

LECTURE 5 Control Structures Part 2 LECTURE 5 Control Structures Part 2 REPETITION STATEMENTS Repetition statements are called loops, and are used to repeat the same code multiple times in succession. The number of repetitions is based on

More information

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011 Oregon State University School of Electrical Engineering and Computer Science CS 261 Recitation 1 Spring 2011 Outline Using Secure Shell Clients GCC Some Examples Intro to C * * Windows File transfer client:

More information

Honors Computer Science Python Mr. Clausen Program 7A, 7B

Honors Computer Science Python Mr. Clausen Program 7A, 7B Honors Computer Science Python Mr. Clausen Program 7A, 7B PROGRAM 7A Turtle Graphics Animation (100 points) Here is the overview of the program. Use functions to draw a minimum of two background scenes.

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

Selection Statement ( if )

Selection Statement ( if ) Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 4 Selection Statement ( if ) Eng. Ibraheem Lubbad October 10, 2016 In this lab we will constructs program that allow

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

The source code for this lab must be submitted in a file named lab4.py. The source code file must contain a file header formatted as in previous labs.

The source code for this lab must be submitted in a file named lab4.py. The source code file must contain a file header formatted as in previous labs. CS 112 - Lab Assignment #4 Conversions) Specification (If Statements and Numeric The purpose of this lab is to gain experience if statements, String to numeric conversions with multiple number bases. The

More information

CSE 115. Introduction to Computer Science I

CSE 115. Introduction to Computer Science I CSE 115 Introduction to Computer Science I Note about posted slides The slides we post will sometimes contain additional slides/content, beyond what was presented in any one lecture. We do this so the

More information

Project 3: RPN Calculator

Project 3: RPN Calculator ECE267 @ UIC, Spring 2012, Wenjing Rao Project 3: RPN Calculator What to do: Ask the user to input a string of expression in RPN form (+ - * / ), use a stack to evaluate the result and display the result

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

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

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab CSC 111 Fall 2005 Lab 6: Methods and Debugging Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab Documented GameMethods file and Corrected HighLow game: Uploaded by midnight of lab

More information

Getting started 7. Saving data 23

Getting started 7. Saving data 23 Contents 1 2 3 4 Getting started 7 Programming code 8 Setting up 10 Exploring IDLE 12 Getting help 14 Saving programs 16 Storing values 18 Adding comments 20 Naming rules 21 Summary 22 Saving data 23 Storing

More information

CMSC 201 Spring 2017 Lab 01 Hello World

CMSC 201 Spring 2017 Lab 01 Hello World CMSC 201 Spring 2017 Lab 01 Hello World Assignment: Lab 01 Hello World Due Date: Sunday, February 5th by 8:59:59 PM Value: 10 points At UMBC, our General Lab (GL) system is designed to grant students the

More information

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington Selection s CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1 Book reference Book: The practice of Computing Using Python 2-nd edition Second hand book

More information

EE 109 Lab 8a Conversion Experience

EE 109 Lab 8a Conversion Experience EE 109 Lab 8a Conversion Experience 1 Introduction In this lab you will write a small program to convert a string of digits representing a number in some other base (between 2 and 10) to decimal. The user

More information

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world! 6.S189 Homework 1 http://web.mit.edu/6.189/www/materials.html What to turn in Do the warm-up problems for Days 1 & 2 on the online tutor. Complete the problems below on your computer and get a checkoff

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

Python Problems MTH 151. Texas A&M University. November 8, 2017

Python Problems MTH 151. Texas A&M University. November 8, 2017 Python Problems MTH 151 Texas A&M University November 8, 2017 Introduction Hello! Welcome to the first problem set for MTH 151 Python. By this point, you should be acquainted with the idea of variables,

More information

#4: While Loop Reading: Chapter3

#4: While Loop Reading: Chapter3 CS 130R: Programming in Python #4: While Loop Reading: Chapter3 Contents Constants While loop Infinite loop Break Continue Constants Similar to variables, but their names are with capital letters and their

More information

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi Shell / Python Tutorial CS279 Autumn 2017 Rishi Bedi Shell (== console, == terminal, == command prompt) You might also hear it called bash, which is the most widely used shell program macos Windows 10+

More information

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an  . Michigan State University CSE 231, Fall 2013 CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?

More information

Computer Programming

Computer Programming Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: for statement in C++ Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 1 Quick Recap

More information

COGS 119/219 MATLAB for Experimental Research. Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control

COGS 119/219 MATLAB for Experimental Research. Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control COGS 119/219 MATLAB for Experimental Research Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control .m files We can write the MATLAB commands that we type at the command window

More information

Department of Computer Science University of Pretoria. Introduction to Computer Science COS 151

Department of Computer Science University of Pretoria. Introduction to Computer Science COS 151 Department of Computer Science University of Pretoria Introduction to Computer Science COS 151 Practical 1 16 February 2018 1 Plagiarism Policy The Department of Computer Science considers plagiarism as

More information

Com S 127 Lab 2. For the first two parts of the lab, start up Wing 101 and use the Python shell window to try everything out.

Com S 127 Lab 2. For the first two parts of the lab, start up Wing 101 and use the Python shell window to try everything out. Com S 127 Lab 2 Checkpoint 0 Please open the CS 127 Blackboard page and click on Groups in the menu at left. Sign up for the group corresponding to the lab section you are attending. Also, if you haven't

More information