CSC 110 - Intro. to Computing Lecture 12: PALGO. Announcements Homework #3 solutions available  Download from Blackboard/web Quiz #3 will be in class.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
COMP 4—Power Tools for the Mind1 PowerTools What’s in the Box? Turing 1: An Introduction to Programming You will learn elementary computer programming.
CSC Intro. to Computing Lecture 17: Even More Robotran!
CSC 110 – Intro to Computing Lecture 14: Midterm Review.
Python November 14, Unit 7. Python Hello world, in class.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Introduction to a Programming Environment
A High-Level Model For Software Development
CIS101 Introduction to Computing Week 12 Spring 2004.
* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed.
5.05 Apply Looping Structures
Programming a computer. What does programming a computer mean ? Programming a computer: Since a computer can only execute machine instructions (encoded.
Computer Science 101 Introduction to Programming.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Python.
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
CSC Intro. to Computing Lecture 13: PALGO. Announcements Midterm is in one week  Time to start reviewing  We will do more review in class Tuesday.
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Variables and Expressions CMSC 201 Chang (rev )
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
PHY 107 – Programming For Science. Announcements  Slides, activities, & solutions always posted to D2L  Note-taking versions before class, for those.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
CSC 107 – Programming For Science. The Week’s Goal.
Programming, an introduction to Pascal
CSC 107 – Programming For Science. Announcements.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
The Hashemite University Computer Engineering Department
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Controlling Program Flow with Decision Structures.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
CSC Programming for Science Lecture 5: Actual Programming.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 2 Basic Computation
Chapter 4 The If…Then Statement
IF statements.
Variables, Expressions, and IO
CMSC201 Computer Science I for Majors Lecture 03 – Operators
More Selections BIS1523 – Lecture 9.
Conditions and Ifs BIS1523 – Lecture 8.
Number and String Operations
T. Jumana Abu Shmais – AOU - Riyadh
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Selection Statements Chapter 3.
Presentation transcript:

CSC Intro. to Computing Lecture 12: PALGO

Announcements Homework #3 solutions available  Download from Blackboard/web Quiz #3 will be in class on Thursday  Covers same topics as the homework  Useful to review material before midterm

Programming Languages Solving problems using a computer, we usually need a program  Program could be written in machine code Series of 1s and 0s that computer understands  Difficult to read & write in machine language  Also very time consuming Programs can contain billions of instructions

Low-Level Languages Close to machine code, but easier to understand  Assembly language replaces 1s & 0s with mnemonics: add, sub, ldi  “C/C++” uses code that is closer to English  Still takes a lot of practice to use them But, also give programmers lots of power  Important when efficiency is critical  But introduces many potential errors

High-level Languages Examples include SQL, and spreadsheet commands  Easier to read & write than low level languages  Less powerful, but also less prone to errors Most programs written in high-level languages  Environment that is most often used for programming: Microsoft Excel

Palgo Programming language we will use  Developed and implemented by Dr. Meyer  Link to PALGO on class webpage  Can be run off of web or download and run on individual machine

Programming Experience Good news! You already have programming experience  Worked with algorithms since beginning of class  Spreadsheets and SQL queries are examples of writing computer programs  This provides you a good base for this discussion

Starting Palgo Web page gets filled with a grid Palgo editing window also pops up

Writing Your First Program Traditional first program is “Hello World”  Prints “Hello World” onto screen  Another example of wacky computer programmers In Palgo, we enter into editing window: print “Hello World” … and then hit the button labeled “Run”

Hello World

Is That All There Is? Programs can be longer than 1 command  Otherwise, Palgo would be really boring… When there are multiple lines*  Palgo 1 st executes first line of the program…  … then executes program’s 2 nd line  … and then executes the 3 rd line  … and continues to execute line-by-line until it reaches the end of the program * While true for simple programs, later we will discuss how to make Palgo do more

Hello Friends Suppose you only want to say hello to specific people  (You really should get out more and be more friendly, but…) In Palgo, we enter into editing window: print “Hello Ishkibble” print “Hello Nevada” … and again hit “Run”

Hello Friends

Hello Friend Decide to get out more and say hello to the user  (Now need to meet a nice girl, settle down, and… sorry, channeling my mother) First, need to get user’s name  To do this we will need to use the input function defined by Palgo

Functions You have already used a number of functions  e.g., … within truth tables  e.g., Min, Max, Sum… in spreadsheets  Write function name, a left parenthesis the function inputs, and a right parenthesis: Min(A2, A3, A4) or Average(A4:A9)  When evaluated, we replace them with their actual value

input() Trying to say hello to the user First need to get their name Do this by using Palgo’s input function: input(“Tell me your name”) When Palgo executes function:  Prints the message  Returns the user’s reply as the result

Hello Friend Text specified in input command Space for the user to enter input

Variables Can use input to get user’s name, but how can we use this?  We need to save this value for later use  To do this we will use a variable Getting user’s name and storing it in a variable: user = input(“Tell me your name”)  After executing this line, whatever the user types will be stored in a variable named user

Variables Every variable in Palgo must have a name  Names start with a letter and then have any letters, numbers, or underscores (“_”) Example variable names:  user, name, Foo, Bar, foo_bar, jamesBond007, peer2peer, r, thisIsALongNameContaining34Letters

Variables Variable is created the first time program assigns it a value  Assign variable a value using the equals sign  For example, following line creates “user”: user = input(“Tell me your name”)  Variable can have only 1 value at a time  So variable’s will store only the newest value if it is assigned a new value later in the program

Variables Palgo uses variable’s value whenever it executes a line using the variable  Similar to spreadsheet using cell’s value whenever it sees a cell name Palgo does NOT reassign variables’ values like a spreadsheet  Palgo ONLY changes variable’s value during assignments  Palgo executes programs line-by-line* and will not automatically propagate changes

Hello Friend Can use print to say “Hello” to the user  So our final program is: name = input(“Tell me your name”) print “Hello ” + name

Hello Friend “Prof. Hertz” is here since that is value of user

Data Type All data objects define the type of data “ One ”, “ 1 ”, 1, and 1.0 are not equal  “ One ”, “ 1 ” are Strings  Strings contain anything inside quotes “Bob is my #1 uncle” “Prof. Hertz is the greatest teacher EVER!”  1 is an int  ints are positive and negative whole numbers 0, -1, 1, 64, , are all ints

Other Palgo Data Types “ One ”, “ 1 ”, 1, and 1.0 are not equal  1.0 is a real  reals include numbers with a decimal 1.2, , , Whenever we reassign a variable, we will also reassign its data type It is not always easy to convert between the different data types

Palgo Operations Palgo does variety of mathematical functions  +, -, *, / will add, subtract, multiply, or divide two numbers  Does not matter whether or not the numbers are stored in a variable

Program Trace Trace programs to see what it will do or why it did something  Important for understanding new code, fixing non-working code, and getting good exam grades  Shows how Palgo executes program step-by- step Shows the line being executed, the value assigned to any variable, and other important information

Program Trace 1 x = y = 8 * 1 3 z = y – 3 4 x = x z = y - x 6 y = y / 2 7 z = “x” 8 y = z + “b” Line#xyz

Program Trace 1 x = y = 8 * 1 3 z = y – 3 4 x = x z = y - x 6 y = y / 2 7 z = “x” 8 y = z + “b” Line#xyz 16 xyz 2 xyz 28 3 xyz xyz 7 5 xyz 1 6 xyz 64 7 xyz x 8 xyz xb

Hello Friends What if one or two people are using the computer?  Want to say hello to either the single user or both users  To do this we first need to ask how many people are at the computer num = input_number("Are there 1 or 2?")  input_number is like input, but returns a number

if---then---else---end num = input_number("Are there 1 or 2?") Program differs depending on num. users We use if—then—else—end to do this  if—then tests boolean (true or false) expression  If true, Palgo executes code between then and else  Otherwise, Palgo executes code between else and end  Palgo will then continue execution after end  (Part of how Palgo does not always execute line-by- line)

Palgo Operators Some operators compute boolean values  == compares if two elements are equal  != compares if two elements are NOT equal  >, =, & <= do the obvious comparisons  a && b returns true if a AND b are true  a || b returns true if either a OR b are true

if---then--else num = input_number("Are there 1 or 2?") if num == 1 then user = input("What is your name?") print "Hello " + user else user = input("What is the first name?") user2=input("What is the second name?") print "Hello " + user + " & " + user2 end Palgo checks if value num variable is equal to 1

if---then--else num = input_number("Are there 1 or 2?") if num == 1 then user = input("What is your name?") print "Hello " + name else user = input("What is the first name?") user2=input("What is the second name?") print "Hello " + name + " & " + name2 end If in this execution the value of num is 1, Palgo will run these statements

if---then--else num = input_number("Are there 1 or 2?") if num == 1 then user = input("What is your name?") print "Hello " + name else user = input("What is the first name?") user2=input("What is the second name?") print "Hello " + name + " & " + name2 end If the value of num is not 1, Palgo runs these statements

if---then--else num = input_number("Are there 1 or 2?") if num == 1 then user = input("What is your name?") print "Hello " + name else user = input("What is the first name?") user2=input("What is the second name?") print "Hello " + name + " & " + name2 end The end keyword marks where Palgo should again execute the program as normal

Hello Friends

What happened?

For Next Lecture Finish reading about Palgo Study for Quiz #3 Play around with Palgo  Run the demo programs  Try writing something on your own  Paint a picture for someone special