1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
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.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Computer Science 101 Introduction to Programming.
Game Programming © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line L.
COMPUTER SCIENCE I C++ INTRODUCTION
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CS107 Introduction to Computer Science Java Basics.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computer Science 101 Introduction to Programming.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Sep 12, 2007Sprenkle - CS1111 Objectives Review  Linux  Why programming languages? Compiled vs. Interpreted Languages Programming in Python  Data types.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Documentation and Comments. What’s a comment? A comment is a simple form of documentation. Documentation is text that you the programmer write to explain.
Input, Output, and Processing
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
Computer Science 101 Introduction to Programming.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Overview of c++ Objectives 1. Understanding the use of the following elements in a c++ program variables constants assignment input output 2. Writing a.
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.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
GCSE Computing: Programming GCSE Programming Remembering Python.
Fundamentals of Programming I Overview of Programming
Agenda Introduction Computer Programs Python Variables Assignment
Whatcha doin'? Aims: To start using Python. To understand loops.
Topics Designing a Program Input, Processing, and Output
Chapter 1: Introduction to computers and C++ Programming
Input and Output Upsorn Praphamontripong CS 1110
IF statements.
Variables, Expressions, and IO
CS190/295 Programming in Python for Life Sciences: Lecture 1
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
An Introduction to Python
Topics Introduction Hardware and Software How Computers Store Data
Topics Designing a Program Input, Processing, and Output
Class 2.
Topics Designing a Program Input, Processing, and Output
7 – Variables, Input and Output
Topics Designing a Program Input, Processing, and Output
Tutorial 10: Programming with javascript
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Computer Programming-1 CSC 111
L L Line CSE 420 Computer Games Lecture #3 Introduction to Python.
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input

2 The Python Programming Language Computers understand a small number of commands in machine language, which consists of all 1's and 0's. High level programming languages, such as Python, C++, Java, provide an easier language for humans to use to tell the computers what to do. The high level language is translated into machine language by a compiler or an interpreter. Python is an interpreted language. Each statement is evaluated by the interpreter as you enter it.

3 Using the Python Interpreter >>> print "Hello World!" Hello World! It's traditional to start with a program that prints out 'Hello World'. In Python, we can do this with one command to the interpreter. The read-evaluate-print cycle: The Python interpreter waits for a command. When the command is entered, Python evaluates the command Python then prints the result. Python statement Python output Python prompt

4 Writing multiple statements We can continue in the interpreter mode: >>> print "Hello world!" Hello world! >>> print "How are you?" How are you? This can get tedious. We can use an editor to write multiple statements that Python can execute all at once: print "Hello world!" print "How are you?" print "Holy Cross rocks!" We will demonstrate the result of running this in class.

5 Adding Comments Comments are not evaluated by the interpreter They are added to the source code to make it easier for programmers to understand the code or to add information. Comments in Python begin with a # Example: # Program: Hello # Purpose: To write out 'Hello World' print "Hello world!" print "How are you?" print "CSCI 110 rocks!"

6 Program Prologues All of your programs for this class must have a prologue: # Program: Hello # Author: Angela Student # Class: MONT 105S # Date: 1/14/09 # Assignment: Lab 1 # Purpose: To write out "Hello World!"

7 Variables (identifiers) If a user types something on a keyboard, the program must read it in and store it. Information is stored in the computer's memory. A variable names a piece of data. It references a location in memory where the information is stored. 'Frank'12 yourName aNumber

8 Assigning values to variables We can assign a value to a variable using the assignment operator. The assignment operator is an equals sign (=). Example: >>> yourName = "Frank" >>> yourName 'Frank' The variable, yourName, now identifies a location in memory where the text string, 'Frank', is stored. We can also assign numeric values to variables: >>> aNumber = 12 >>> aNumber 12

9 Reading Text from the Keyboard We use variables to read information in from the keyboard: The raw_input( ) command is used to read in text: >>> name = raw_input("Please enter your name: ") Please enter your name: Angela >>> name Angela 1) raw_input( ) will output the text within the brackets and then wait for the user response. 2) The user response is assigned to the name variable.

10 Reading in a Number Use the command, input( ), to enter a number from the keyboard. Example: >>> aNumber = input("Please enter a number: ") Please enter a number: 12 >>> aNumber 12

11 An example Write a program that asks for a user's name, and then says hello using the user's name. # Program: Hello # Purpose: To say hello to the user yourName = raw_input("Hello! What is your name? ") print "Hello " + yourName + "!"

12 Naming Variables Rules for naming variables: 1) Do not use spaces 2) Variable names must start with a letter 3) Do not use special characters (%, *, /, etc) 4) Case (upper vs. lower case letters) matters. Good variable names: age_of_dog TaxRate98 printHeading Not allowed: age%98TaxRateage-of-catmy dog