How Do Robots Find Their Way?

Size: px
Start display at page:

Download "How Do Robots Find Their Way?"

Transcription

1 How Do Robots Find Their Way? Conditionals and Repetition

2

3

4 Learning Objectives Learn basic programming concepts (variables, if statements, loops, and functions) and write simple programs using these concepts.

5 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

6 Robots are dumb What does a robot need to know how to do to solve a maze? What commands and behaviors would be useful?

7

8

9 Can I move forward?

10 If these is empty space, then move forward

11 If these is empty space, then move forward Conditional

12 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

13 It is raining Wear a raincoat

14 Grade is at least 50 Pass the class

15 There is empty space in front of the robot The robot moves forward

16 True or false, aka Boolean value There is empty space in front of the robot The robot moves forward

17 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

18 and Everything has to be true

19 and true and true = true true and false and true = false false and false = false

20 or Only one thing has to be true

21 or true or true = true true or false or true = true false or false = false

22 What will the result of this expression be? (true and (not false) or (true and not false))

23 What will the result of this expression be? ((not false) or (false and (not true)) and false)

24 What will the result of this expression be? ((not false) or (false and (not true)) and false)

25 Using the logic at right, suppose our robot decides to pivot left. Which of the following can be true? (a) (b) (c) There is a wall only behind the robot and to its left. There is a wall only behind the robot. There is a wall to the left and right of the robot, but not in front. if (wall on left) and (no wall on right) and (no wall on front): then pivot right otherwise: pivot left Text : a 90277: b 90279: c

26 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

27 Anything that results in true or false can go into the if part of a conditional

28 I am buying a movie ticket and I am a student I will get a discount on the price

29 My percentage is at least 77 and my percentage is at most 79 My grade is B+

30 The battery is dead or there is no gas The car will not start

31 Not married and not engaged and like it Put a ring on it

32 Boolean Expressions in Python Type the following into the shell: 5 == 5

33 Boolean Expressions in Python Type the following into the shell: 5 == 5 Equality Operator

34 Boolean Expressions in Python Type the following into the shell: 5 == 4

35 Boolean Expressions in Python Type the following into the shell: 5!= 4

36 Boolean Expressions in Python Type the following into the shell: 5!= 4 Inequality Operator

37 If-Statements in Python Type the following into the shell: if 5 == 5: print(1)

38 If-Statements in Python Here is the syntax for if-statements in Python: if <a Boolean expression>: <code to run if the Boolean expression is true>

39 If-Statements in Python Here is the syntax for if-statements in Python: Something that must be either true or false if <a Boolean expression>: <code to run if the Boolean expression is true>

40 If-Statements in Python Here is the syntax for if-statements in Python: "Then" after this we must if <a Boolean expression>: indent <code to run if the Boolean expression is true>

41 If-Statements in Python Here is the syntax for if-statements in Python: if <a Boolean expression>: <code to run if the Boolean expression is true> Indentation tells Python how much code is part of the "then"

42 If-Statements in Python Here is the syntax for if-statements in Python: if <a Boolean expression>: <code to run if the Boolean expression is true> Everything with the same indentation will run when the Boolean expression is true

43 If-Statements in Python What will get printed here (if anything)? if 7 > 6 and (3 > 4 or 4 < 5): print(1)

44 If-Else Statements in Python Here is the syntax for if-else statements in Python: if <a Boolean expression>: <code to run if Boolean expression is true> else: <code to run if the Boolean expression is false>

45 If-Else Statements in Python Here is the syntax for if-else statements in Python: if <a Boolean expression>: <code to run if Boolean expression is true> else: "Otherwise" <code to run if the Boolean expression is false>

46 What is the output? x = 25 if x < 15: if x > 8: print(1) else: print(2) else: print(3) Text : : : : : : 2 3

47 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

48 How would you find your way out of a maze?

49 Right-Hand Rule Same idea, but with left hand:

50 One Move with Right-Hand Rule 1. If there is empty space to my right, then pivot right and step forward. 2. Otherwise, if there is empty space in front of me, then step forward. 3. Otherwise, if there is empty space to my left, then pivot left and step forward. 4. Otherwise pivot right without stepping forward.

51

52

53 There is a wall, so no

54 No wall in front, so yes!

55

56 There is a wall, so no

57 There is a wall, so no

58 No wall to the left, so yes!

59

60

61 Maze Solving in Python Remember, functions (aka routines) can "return" results!

62 Maze Solving in Python Suppose these functions existed in Python, and returned Boolean values: emptyspacetoright() emptyspacetoleft() emptyspaceinfront()

63 Maze Solving in Python Suppose these functions existed in Python, and simply caused the robot to take the associated action: pivotleft() pivotright() stepforward()

64 Maze Solving in Python Then one step in maze-solving would look like this: if emptyspacetoright(): pivotright() stepforward() elif emptyspaceinfront(): stepforward() elif emptyspacetoleft(): pivotleft() stepforward() else: pivotright()

65 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

66

67 How many times do I move before I m out of the maze??

68 Instead: I ll just keep moving until I get out

69 Loops Drive the same track multiple times: each lap is exactly the same

70 while loop Drive the track while the race is not over

71 while not at exit, continue making moves

72 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

73 While Loops in Python while <Boolean value>: <loop body>

74 While Loops in Python while <Boolean value>: <loop body> While loop: Drive around the track...

75 While Loops in Python while <Boolean value>: <loop body>...running this code again on every lap around the track...

76 While Loops in Python while <Boolean value>: <loop body>...until this Boolean is no longer true

77 While Loops in Python while <Boolean value>: <loop body> And yes, the colon the indentation are still important!

78 Example x = 0 while x < 2: x = x + 1 print(x)

79 Example x is given a value of 0 x = 0 while x < 2: x = x + 1 print(x)

80 Example The Boolean expression is checked x = 0 while x < 2: x = x + 1 print(x)

81 Example x = 0 while x < 2: x = x + 1 print(x) 1 is added to x, so x is now 1

82 Example x = 0 while x < 2: x = x + 1 print(x) 1 is printed to the shell

83 Example x = 0 while x < 2: x = x + 1 print(x) Lap one is now finished

84 Example x = 0 while x < 2: x = x + 1 print(x) so check the Boolean expression again

85 Example x = 0 while x < 2: x = x + 1 print(x) x becomes 2

86 Example x = 0 while x < 2: x = x + 1 print(x) 2 is printed to the shell

87 Example x = 0 while x < 2: x = x + 1 print(x) Lap two is now finished

88 Example x = 0 while x < 2: x = x + 1 print(x) so check the Boolean expression again Now that x is 2, the expression is false, and we're done!

89 What is the output? x = 6 while x > 4: print(x) x = x - 1 Text : : : : :

90 What is the output? n = 3 while n > 0: if n == 5: n = -99 print(n) n = n + 1 Text : : : :

91 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

92 What does "driving a lap" mean in the context of robot maze solving?

93 Maze Solving Logic 1. while I have not reached the exit: 1. If there is empty space to my right, then pivot right and step forward. 2. Otherwise, if there is empty space in front of me, then step forward. 3. Otherwise, if there is empty space to my left, then pivot left and step forward. 4. Otherwise pivot right without stepping forward.

94 Maze Solving in Python Suppose that in addition to our previous functions, the following was also defined in Python: reachedexit()

95 Maze Solving in Python Then our whole maze-solving logic would look like this: while not reachedexit(): if emptyspacetoright(): pivotright() stepforward() elif emptyspaceinfront(): stepforward() elif emptyspacetoleft(): pivotleft() stepforward() else: pivotright()

96 Part 1 Robot behavior Conditionals Logic More complex conditionals Maze solving Part 2 Repeating behaviour While loops Loops in Maze Solving

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

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

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

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

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1 Pupil Name Year Teacher Target Level Spelling Test No 1 Spelling Test No 2 Spelling Test No 3 1) 2) 3) 4) 5) 1) 2) 3) 4) 5) 1) 2) 3) 4) 5) Spelling Test No 4 Spelling Test No 5 Spelling Test No 6 1) 2)

More information

3. Conditional Execution

3. Conditional Execution 3. Conditional Execution Topics: Boolean values Relational operators if statements The Boolean type Motivation Problem: Assign positive float values to variables a and b and print the values a**b and b**a.

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

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

SELECTION. (Chapter 2)

SELECTION. (Chapter 2) SELECTION (Chapter 2) Selection Very often you will want your programs to make choices among different groups of instructions For example, a program processing requests for airline tickets could have the

More information

Chapter 3. Iteration

Chapter 3. Iteration Chapter 3 Iteration Iteration Iteration is the form of program control that allows us to repeat a section of code. For this reason this form of control is often also referred to as repetition. The programming

More information

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

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block THE IF STATEMENT The if statement is used to check a condition: if the condition is true, we run a block of statements (called the if-block), elsewe process another block of statements (called the else-block).

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

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

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Boolean Expressions and if 9/14/2007

Boolean Expressions and if 9/14/2007 Boolean Expressions and if 9/14/2007 1 Opening Discussion Do you have any questions about the quiz? Let's look at solutions to the interclass problem. Minute essay questions. What functions will we be

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

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 15 Branching : IF ELSE Statement We are looking

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

Repetition Algorithms

Repetition Algorithms Repetition Algorithms Repetition Allows a program to execute a set of instructions over and over. The term loop is a synonym for a repetition statement. A Repetition Example Suppose that you have been

More information

Control and Environments Fall 2017 Discussion 1: August 30, Control. If statements. Boolean Operators

Control and Environments Fall 2017 Discussion 1: August 30, Control. If statements. Boolean Operators CS 61A Control and Environments Fall 2017 Discussion 1: August 30, 2017 1 Control Control structures direct the flow of logic in a program. For example, conditionals (if-elif-else) allow a program to skip

More information

CONTROL AND ENVIRONMENTS 1

CONTROL AND ENVIRONMENTS 1 CONTROL AND ENVIRONMENTS 1 COMPUTER SCIENCE 61A September 1, 2016 1 Control Control structures direct the flow of logic in a program. For example, conditionals (ifelif-else) allow a program to skip sections

More information

3. Conditional Execution

3. Conditional Execution 3. Conditional Execution Topics: Boolean values Relational operators if statements The Boolean type Motivation Problem: Assign positive float values to variables a and b and print the values a**b and b**a.

More information

Comp 151. Control structures.

Comp 151. Control structures. Comp 151 Control structures. admin quiz this week believe it or not only 2 weeks from exam. one a week each week after that. idle debugger Debugger: program that will let you look at the program as it

More information

CS 61A Control and Environments Spring 2018 Discussion 1: January 24, Control. If statements. Boolean Operators

CS 61A Control and Environments Spring 2018 Discussion 1: January 24, Control. If statements. Boolean Operators CS 61A Control and Environments Spring 2018 Discussion 1: January 24, 2018 1 Control Control structures direct the flow of logic in a program. For example, conditionals (if-elif-else) allow a program to

More information

Making Decisions In Python

Making Decisions In Python Making Decisions In Python In this section of notes you will learn how to have your programs choose between alternative courses of action. Decision Making Is All About Choices My next vacation? Images:

More information

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action.

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action. Chapter 5 Conditional and Iterative Statements Statement Statement are the instructions given to the computer to perform any kind of action. Types of Statement 1. Empty Statement The which does nothing.

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

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

CONTROL AND HIGHER ORDER FUNCTIONS 1

CONTROL AND HIGHER ORDER FUNCTIONS 1 CONTROL AND HIGHER ORDER FUNCTIONS 1 COMPUTER SCIENCE 61A September 3, 2015 1 Control Control structures direct the flow of logic in a program. For example, conditionals (ifelif-else) allow a program to

More information

KAREL JR 3 STUDENT JOURNAL REVISED APRIL 19, 2017 NAME SCHOOL, CLASS, PERIOD

KAREL JR 3 STUDENT JOURNAL REVISED APRIL 19, 2017 NAME SCHOOL, CLASS, PERIOD KAREL JR 3 STUDENT JOURNAL REVISED APRIL 19, 2017 NAME DATE STARTED DATE COMPLETED SCHOOL, CLASS, PERIOD Copyright 2016, 2017 NCLab Inc. 2 3 TABLE OF CONTENTS: WELCOME TO YOUR JOURNAL 4 SECTION 11: USING

More information

1. The programming language C is more than 30 years old. True or False? (Circle your choice.)

1. The programming language C is more than 30 years old. True or False? (Circle your choice.) Name: Section: Grade: Answer these questions while viewing the assigned videos. Not sure of an answer? Ask your instructor to explain at the beginning of the next class session. You can then fill in your

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

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

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

Quiz. Introduction: Python. In this project, you ll make a quiz game to challenge your friends. Activity Checklist.

Quiz. Introduction: Python. In this project, you ll make a quiz game to challenge your friends. Activity Checklist. Python 1 Quiz All Code Clubs must be registered. Registered clubs appear on the map at codeclub.org.uk - if your club is not on the map then visit jumpto.cc/18cplpy to find out what to do. Introduction:

More information

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration STATS 507 Data Analysis in Python Lecture 2: Functions, Conditionals, Recursion and Iteration Functions in Python We ve already seen examples of functions: e.g., type()and print() Function calls take the

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

Control and Environments Fall 2017 Discussion 1: August 30, 2017 Solutions. 1 Control. If statements. Boolean Operators

Control and Environments Fall 2017 Discussion 1: August 30, 2017 Solutions. 1 Control. If statements. Boolean Operators CS 61A Control and Environments Fall 2017 Discussion 1: August 30, 2017 Solutions 1 Control Control structures direct the flow of logic in a program. For example, conditionals (if-elif-else) allow a program

More information

CSE 115. Introduction to Computer Science I

CSE 115. Introduction to Computer Science I CSE 115 Introduction to Computer Science I Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu Announcements Lab activites/lab exams submit regularly to autograder.cse.buffalo.edu

More information

The L Line. The Express Line to Learning. Wiley Publishing All Rights Reserved.

The L Line. The Express Line to Learning. Wiley Publishing All Rights Reserved. L The L Line The Express Line to Learning Wiley Publishing. 2007. All Rights Reserved. 3 Taking Control Stations Along the Way Using the if statement Creating a condition Using else to work with false

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

ENGR 101 Engineering Design Workshop

ENGR 101 Engineering Design Workshop ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as

More information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

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

LN #2 (3 Hrs) Variables, Sequence Boolean Logic & Selection CTPS Department of CSE,Coimbatore

LN #2 (3 Hrs) Variables, Sequence Boolean Logic & Selection CTPS Department of CSE,Coimbatore LN #2 (3 Hrs) Variables, Sequence Boolean Logic & Selection CTPS 2018 Objectives To understand variables and their values. To study the computational structure, form and functional elements for sequence

More information

MITOCW watch?v=0jljzrnhwoi

MITOCW watch?v=0jljzrnhwoi MITOCW watch?v=0jljzrnhwoi The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

CSE 113 A. Announcements - Lab

CSE 113 A. Announcements - Lab CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure

More information

CS177 Recitation. Functions, Booleans, Decision Structures, and Loop Structures

CS177 Recitation. Functions, Booleans, Decision Structures, and Loop Structures CS177 Recitation Functions, Booleans, Decision Structures, and Loop Structures Functions Collection of instructions that perform a task as: o Printing your name and course. o Calculating the average of

More information

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017 SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

RECURSION AND LINKED LISTS 3

RECURSION AND LINKED LISTS 3 RECURSION AND LINKED LISTS 3 COMPUTER SCIENCE 61A July 1, 2014 1 Termination and Warmup A function is recursive if executing a call to the function requires another call to the same function, called a

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

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Structure and Interpretation of Computer Programs Spring 2016 Test 1

Structure and Interpretation of Computer Programs Spring 2016 Test 1 CS 6A Structure and Interpretation of Computer Programs Spring 206 Test INSTRUCTIONS You have 2 hours to complete the exam. The exam is open book, open notes, closed computer, closed calculator. The official

More information

Python Activity 7: Looping Structures WHILE Loops

Python Activity 7: Looping Structures WHILE Loops Python Activity 7: Looping Structures WHILE Loops How can I get my code to repeat output or processes? Learning Objectives Students will be able to: Content: Explain the three parts of a loop Explain the

More information

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Flow of Control. Flow of control The order in which statements are executed. Transfer of control 1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

Exercise 6 - Addressing a Message

Exercise 6 - Addressing a Message Exercise 6 - Addressing a Message All e-mail messages have to include an address for an e-mail to be delivered, just as a normal letter has to have a house address. An e-mail address is made up of: a user

More information

Python for Non-programmers

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

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

CS1 Lecture 3 Jan. 18, 2019

CS1 Lecture 3 Jan. 18, 2019 CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due

More information

roboturtle Documentation

roboturtle Documentation roboturtle Documentation Release 0.1 Nicholas A. Del Grosso November 28, 2016 Contents 1 Micro-Workshop 1: Introduction to Python with Turtle Graphics 3 1.1 Workshop Description..........................................

More information

C ONTROL AND H IGHER O RDER F UNCTIONS

C ONTROL AND H IGHER O RDER F UNCTIONS Name: Date: Period: Name 2: Name 3: Name 4: 20 points C ONTROL AND H IGHER O RDER F UNCTIONS (Review questions from readings and labs) 1 Instructions: Complete all 9S CIENCE discussion C OMPUTER 61A questions.

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

CS Summer 2013

CS Summer 2013 CS 1110 - Summer 2013 intro to programming -- how to think like a robot :) we use the Python* language (www.python.org) programming environments (many choices): Eclipse (free from www.eclipse.org), or

More information

Programming Logic and Design Sixth Edition

Programming Logic and Design Sixth Edition Objectives Programming Logic and Design Sixth Edition Chapter 4 Making Decisions In this chapter, you will learn about: Evaluating Boolean expressions to make comparisons The relational comparison operators

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

Line tracking sensors and algorithms

Line tracking sensors and algorithms Line tracking sensors and algorithms Posted on February 28, 2008, by Ibrahim KAMAL, in Robotics, tagged Line tracking is a very important notion in the world of robotics as it give to the robot a precise,

More information

CS 1301 Exam 1 Answers Fall 2009

CS 1301 Exam 1 Answers Fall 2009 Page 1/6 CS 1301 Fall 2009 Exam 1 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1301 Exam

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

Unit 7. 'while' Loops

Unit 7. 'while' Loops 1 Unit 7 'while' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment

More information

Python Activity 5: Boolean Expressions and Selection Statements

Python Activity 5: Boolean Expressions and Selection Statements Python Activity 5: Boolean Expressions and Selection Statements "True or False and making choices" Learning Objectives Students will be able to: Content: Explain the three types of programming structures

More information

C/C++ Programming Lecture 7 Name:

C/C++ Programming Lecture 7 Name: 1. The increment (++) and decrement (--) operators increase or decrease a variable s value by one, respectively. They are great if all you want to do is increment (or decrement) a variable: i++;. HOWEVER,

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

CS 105 Lab As a review of what we did last week a. What are two ways in which the Python shell is useful to us?

CS 105 Lab As a review of what we did last week a. What are two ways in which the Python shell is useful to us? 1 CS 105 Lab 3 The purpose of this lab is to practice the techniques of making choices and looping. Before you begin, please be sure that you understand the following concepts that we went over in class:

More information

3 Programming. Jalal Kawash Mandatory: Chapter 5 Section 5.5 Jalal s resources: How to movies and example programs available at:

3 Programming. Jalal Kawash Mandatory: Chapter 5 Section 5.5 Jalal s resources: How to movies and example programs available at: 3 Programming 1 Mandatory: Chapter 5 Section 5.5 Jalal s resources: How to movies and example programs available at: http://pages.cpsc.ucalgary.ca/~kawash/peeking/alice-how-to.html JT s resources: www.cpsc.ucalgary.ca/~tamj/203/extras/alice

More information

Using Functions in Alice

Using Functions in Alice Using Functions in Alice Step 1: Understanding Functions 1. Download the starting world that goes along with this tutorial. We will be using functions. A function in Alice is basically a question about

More information

Built-in functions. You ve used several functions already. >>> len("atggtca") 7 >>> abs(-6) 6 >>> float("3.1415") >>>

Built-in functions. You ve used several functions already. >>> len(atggtca) 7 >>> abs(-6) 6 >>> float(3.1415) >>> Functions Built-in functions You ve used several functions already len("atggtca") 7 abs(-6) 6 float("3.1415") 3.1415000000000002 What are functions? A function is a code block with a name def hello():

More information

Introduction to the Java Basics: Control Flow Statements

Introduction to the Java Basics: Control Flow Statements Lesson 3: Introduction to the Java Basics: Control Flow Statements Repetition Structures THEORY Variable Assignment You can only assign a value to a variable that is consistent with the variable s declared

More information

SCHEME AND CALCULATOR 5b

SCHEME AND CALCULATOR 5b SCHEME AND CALCULATOR 5b COMPUTER SCIENCE 6A July 25, 203 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Python for Informatics

Python for Informatics Python for Informatics Exploring Information Version 0.0.6 Charles Severance Chapter 3 Conditional execution 3.1 Boolean expressions A boolean expression is an expression that is either true or false.

More information

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

Python Unit

Python Unit Python Unit 1 1.1 1.3 1.1: OPERATORS, EXPRESSIONS, AND VARIABLES 1.2: STRINGS, FUNCTIONS, CASE SENSITIVITY, ETC. 1.3: OUR FIRST TEXT- BASED GAME Python Section 1 Text Book for Python Module Invent Your

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

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION LESSON 15 NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION OBJECTIVE Learn to work with multiple criteria if statements in decision making programs as well as how to specify strings versus integers in

More information

WELCOME UVAHS REMEDY INCIDENT MANAGEMENT

WELCOME UVAHS REMEDY INCIDENT MANAGEMENT WELCOME UVAHS REMEDY INCIDENT MANAGEMENT 1 Course Material Index Updating and Resolving Incidents Assigning, Re-Assigning, Updating and Resolving Incidents Additional Modules: Introduction Logging In and

More information

Data 8 Final Review #1

Data 8 Final Review #1 Data 8 Final Review #1 Topics we ll cover: Visualizations Arrays and Table Manipulations Programming constructs (functions, for loops, conditional statements) Chance, Simulation, Sampling and Distributions

More information

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

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

Lecture 8: Conditionals & Control Flow (Sections ) CS 1110 Introduction to Computing Using Python

Lecture 8: Conditionals & Control Flow (Sections ) CS 1110 Introduction to Computing Using Python http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 8: Conditionals & Control Flow (Sections 5.1-5.7) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information: CSE 131 Introduction to Computer Science Fall 2016 Given: 29 September 2016 Exam I Due: End of Exam Session This exam is closed-book, closed-notes, no electronic devices allowed The exception is the "sage

More information

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

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful

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

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

KAREL UNIT 5 STUDENT JOURNAL REVISED APRIL 19, 2017 NAME SCHOOL, CLASS, PERIOD

KAREL UNIT 5 STUDENT JOURNAL REVISED APRIL 19, 2017 NAME SCHOOL, CLASS, PERIOD KAREL UNIT 5 STUDENT JOURNAL REVISED APRIL 19, 2017 NAME DATE STARTED DATE COMPLETED SCHOOL, CLASS, PERIOD Copyright 2016, 2017 NCLab Inc. 2 3 TABLE OF CONTENTS: WELCOME TO YOUR JOURNAL 4 SECTION 21: PROBABILITY

More information

BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17)

BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17) BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17) 1 Learning Outcomes At the end of this lecture, you should be able to: 1. Explain the concept of selection control structure

More information

Control of Flow. There are several Python expressions that control the flow of a program. All of them make use of Boolean conditional tests.

Control of Flow. There are several Python expressions that control the flow of a program. All of them make use of Boolean conditional tests. Control of Flow There are several Python expressions that control the flow of a program. All of them make use of Boolean conditional tests. If Statements While Loops Assert Statements 6 If Statements if

More information

Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017

Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017 Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017 K. Zhang BMGT 404 The modulus operator It works on integers

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 18 Switch Statement (Contd.) And Introduction to

More information

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) Technology & Information Management Instructor: Michael Kremer, Ph.D. Database Program: Microsoft Access Series DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) AGENDA 3. Executing VBA

More information

CS112 Lecture: Repetition Statements

CS112 Lecture: Repetition Statements CS112 Lecture: Repetition Statements Objectives: Last revised 2/18/05 1. To explain the general form of the java while loop 2. To introduce and motivate the java do.. while loop 3. To explain the general

More information

Fundamentals of Programming (Python) Control Structures. Sina Sajadmanesh Sharif University of Technology Fall 2017

Fundamentals of Programming (Python) Control Structures. Sina Sajadmanesh Sharif University of Technology Fall 2017 Fundamentals of Programming (Python) Control Structures Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Python: How to Program 1 st Edition Outline 1. Control Structures

More information