0% found this document useful (0 votes)
38 views

Introduction To Computers, Programs, and Python

This document introduces Python programming. It discusses that Python is a general purpose, interpreted, object-oriented programming language. It provides objectives for the chapter, which include understanding computer basics, writing a simple Python program, and explaining Python syntax. It presents examples of simple Python programs and describes program statements, comments, and indentation. It also covers programming style, documentation, and types of errors. Finally, it introduces graphical user interface programming using the Turtle and Tkinter packages.

Uploaded by

Mariam Fuad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Introduction To Computers, Programs, and Python

This document introduces Python programming. It discusses that Python is a general purpose, interpreted, object-oriented programming language. It provides objectives for the chapter, which include understanding computer basics, writing a simple Python program, and explaining Python syntax. It presents examples of simple Python programs and describes program statements, comments, and indentation. It also covers programming style, documentation, and types of errors. Finally, it introduces graphical user interface programming using the Turtle and Tkinter packages.

Uploaded by

Mariam Fuad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Chapter 1

Introduction to Computers,
Programs, and Python

1
Objectives
 To understand computer basics, programs, and operating
systems (§§1.2-1.4).
 To write and run a simple Python program (§1.5).
 To explain the basic syntax of a Python program (§1.5).
 To describe the history of Python (§1.6).
 To explain the importance of, and provide examples of,
proper programming style and documentation (§1.7).
 To explain the differences between syntax errors,
runtime errors, and logic errors (§1.8).
 To create a basic graphics program using Turtle (§1.9).
2
What is Python?
General Purpose Interpreted Object-Oriented
Python is a general purpose programming
language. That means you can use Python to write
code for any programming tasks. Python are now
used in Google search engine, in mission critical
projects in NASA, in processing financial
transactions at New York Stock Exchange.

3
What is Python?
General Purpose Interpreted Object-Oriented
Python is interpreted, which means that python
code is translated and executed by an interpreter
one statement at a time. In a compiled language, the
entire source code is compiled and then executed
altogether.

4
What is Python?
General Purpose Interpreted Object-Oriented
Python is an object-oriented programming
language. Data in Python are objects created from
classes. A class is essentially a type that defines the
objects of the same kind with properties and
methods for manipulating objects. Object-oriented
programming is a powerful tool for developing
reusable software.

5
Python’s History
 created by Guido van Rossum in Netherlands in 1990
 Open source

6
Python 2 vs. Python 3

Python 3 is a newer version, but it is not


backward compatible with Python 2.
That means if you write a program
using Python 2, it may not work on
Python 3.

7
Launch Python
You can use the following python online
compiler to run python program:

https://www.onlinegdb.com/

8
Launch Python IDLE
https://www.onlinegdb.com/

9
A Simple Python Program

Listing 1.1
# Display two messages
print("Welcome to Python")
print("Python is fun")

IMPORTANT NOTE:
(1) To enable the buttons, you must download the entire
Welcome slide file slide.zip and unzip the files into a directory (e.g.,
c:\slide). (2) You must have installed Python and set
python bin directory in the environment path. (3) If you are
Run
using Office 2010, check PowerPoint2010.doc located in
the same folder with this ppt file.
10
animation

Trace a Program Execution


Execute a statement

# Display two messages


print("Welcome to Python")
print("Python is fun")

11
animation

Trace a Program Execution


Execute a statement

# Display two messages


print("Welcome to Python")
print("Python is fun")

12
Two More Simple Examples

WelcomeWithThreeMessages Run

ComputeExpression Run

13
Companion
Website Supplements on the Companion
Website

 See Supplement I.B for installing and


configuring Python
 See Supplement I.C for developing
Python programs from Eclipse

www.cs.armstrong.edu/liang/py

14
Anatomy of a Python Program

 Statements
 Comments
 Indentation

15
Statement
A statement represents an action or a sequence of
actions. The statement print("Welcome to Python")
in the program in Listing 1.1 is a statement to
display the greeting "Welcome to Python“.

# Display two messages


print("Welcome to Python")
print("Python is fun")

16
Indentation
The indentation matters in Python. Note that the statements are entered from
the first column in the new line. It would cause an error if the program is
typed as follows:

# Display two messages


print("Welcome to Python")
print("Python is fun")

17
Special Symbols

Character Name Description

() Opening and closing Used with functions.


parentheses
# Pound sign Precedes a comment line.

" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
''' ''' Opening and closing Enclosing a paragraph comment.
quotation marks

18
Programming Style and
Documentation

AppropriateComments
Proper Indentation and Spacing
Lines

19
Appropriate Comments

Include a summary at the beginning of the program to explain what the program
does, its key features, its supporting data structures, and any unique techniques
it uses.

Include your name, class section, instructor, date, and a brief description at the
beginning of the program.

20
Proper Indentation and Spacing

 Indentation
 Indent four spaces.
 A consistent spacing style makes programs clear and easy to read, debug,
and maintain.

 Spacing
 Use blank line to separate segments of the code.

21
Programming Errors

 Syntax Errors
 Error in code construction
 Runtime Errors
 Causes the program to abort
 Logic Errors
 Produces incorrect result

22
Getting Started with GUI Programming
Why GUI? Turtle Tkniter

GUI is a great pedagogical tool to motivate studetns


and stimulate student interests in programming.

23
Getting Started with GUI Programming
Why GUI? Turtle Tkniter

A simple way to start graphics programming is to


use Python built-in Turtle package.

A Turtule Example

Run

24
Getting Started with GUI Programming
Why GUI? Turtle Tkniter

Later in the book, we will also introduce Tkinter for


developing comprehensive GUI applications.

A Tkinter Example

Run

25

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy