Python Fundamentals: Hello World! Eric Shook Department of Geography Kent State University.

Slides:



Advertisements
Similar presentations
Python Basics: Statements Expressions Loops Strings Functions.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Python Programming Chapter 2: Variables, expressions, and statements Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Introduction to Python
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Introduction to scripting
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Introduction to Python
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
PhD, Senior Lecturer, Baimuratov Olimzhon A LGORITHMS & P ROGRAMMING (P YTHON ) Lecture 2 From SDU:
Input, Output, and Processing
Java Programming, Second Edition Chapter One Creating Your First Java Program.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Variables, Expressions and Statements
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏ Sec 9-7 Web Design.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Variables, Types, Expressions Intro2CS – week 1b 1.
Data Manipulation Variables, Data Types & Math. Aug Variables A variable is a name (identifier) that points to a value. They are useful to store.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code.
Whatcha doin'? Aims: To start using Python. To understand loops.
CMSC201 Computer Science I for Majors Lecture 02 – Intro to Python
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python Let’s get started!.
IF statements.
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Presented By S.Yamuna AP/IT
Data types and variables
Introduction to Scripting
Learning to Program in Python
Week 3 Computer Programming Learning Objective:
Introduction to Python
Learning Outcomes –Lesson 4
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Variables, Data Types & Math
Variables, Data Types & Math
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Variables, Data Types & Math
Beginning Python Programming
JavaScript: Introduction to Scripting
Chapter 1: Programming Basics, Python History and Program Components
An Overview of C.
Starter Activities GCSE Python.
Hardware is… Software is…
Python fundamental.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Python Fundamentals: Hello World! Eric Shook Department of Geography Kent State University

The Python Programming Language Python is an Open Source programming language It is easy to use and easy to learn how to program Python website: Additional links:  Documentation:  Tutorial:  Reference Manual: Many online resources:  Google will help

A Python Statement mystring = "Hello World!"

Statement Breakdown mystring = "Hello World!" Variable Variables can hold values (think back to math class). They can be referred by a name such as x, name or this_is_a_variable

Statement Breakdown mystring = "Hello World!" Assignment The equals sign assigns the value: "Hello World!" to the variable: mystring

Statement Breakdown mystring = "Hello World!" Value Variable values can be: strings such as "hello" or numbers such as 123 or 3.14

Statement Breakdown mystring = "Hello World!" Statement A statement is a single command that tells the computer (Python interpreter) to do something.

Try it mystring = "Hello World!" helloworld.py $ nano helloworld.py $ python helloworld.py Command-line Terminal

Try it mystring = "Hello World!" helloworld.py $ nano helloworld.py $ python helloworld.py Command-line Terminal Nothing?

Print Function Statement Breakdown print(mystring) Function call A function is a defined piece of Python code that can be called upon such as a 'print' function that prints information to the screen: function_name( arguments ) Arguments Arguments also known as parameters are passed into functions. This parameter is a variable, but strings and numbers can also be arguments. (myvar, "string 1", 2345, 3.14)

Try it mystring = "Hello World!" print(mystring) helloworld.py $ nano helloworld.py $ python helloworld.py Hello World! Command-line Terminal Success!

Case Sensitivity Python is case-sensitive meaning that uppercase and lowercase letters may change the meaning of commands print Print PRINT pRINT PrInT Only 'print' can be used to print information to the screen

Bugs $ python helloworld.py File "helloworld.py", line 4 ^ SyntaxError: invalid syntax These are bugs and errors that you will see Not these bugs

Common Bugs Attention to detail is vital when programming, because the smallest error and cause hard-to-find bugs. Each of the lines below contain one error. Can you spot them all? mystring="Hello World!") print(Hello World") Print(mystring) mystring="He said "hi" how are you"

Common Bugs Fixed Attention to detail is vital when programming, because the smallest error and cause hard-to-find bugs. Each of the lines below contain one error. Can you spot them all? mystring="Hello World!") print("Hello World") print(mystring) mystring="He said 'hi' how are you"

Basic Data Types Integer: 2, 10, -5, Floating point:3.14, , -1.0 String:"Hello World!", "a", "I am tweeting #twitter" Boolean:True, False NoneThis is a special type that uses the word None to literally mean there is nothing here. None is different than "", 0, and 0.0, which indicate a value for the other types.

Expressions Variables and numbers can be combined in mathematical expressions that will be evaluated or calculated. Mathematical expressions combined with logical statements enable Python to be used for spatial data processing ExpressionValue x = 2 + 2the variable x is equal to the value 4 y = x * 3if x is equal to 4 then the value of y is 12 x = x + 2if x is equal to 4 then the new value of x is 6 x = 4 – 2the variable x is now equal to the value 2 x = 4 / 2the variable x is equal to the value 2

Comments i=0 # This is a comment # i=1 print "i=",i # Write the value of i i=0 The Result Comments Comments allow programmers to leave plain text explanations of code. Comments are started with a hash tag (#) and everything after the '#' is ignored by Python.

Try It 1.Create a Python program with 5 variables. Each variable should be a different basic type 2.Print the value of each variable 3.Try printing a string and a variable like this: x=5 print("x=",x) 4.Create 3 mathematical expressions and print out the result. Check to make sure the result is correct. 5.Create 2 variables that have values that are strings. Add the variables together and print out the result. Is it what you expect? If the result is unexpected look in the manual to understand the result. 6.Add a comment to your program. Run it again to see if anything changed.