SlideShare a Scribd company logo
Python Programming:
An Introduction to
Computer Science
Chapter 1
Computers and Programs
The Magic of Python
When you start Python, you will see
something like:
Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
The Magic of Python
 The “>>>” is a Python prompt indicating that
Python is ready for us to give it a command.
These commands are called statements.
 >>> print("Hello, world“)
Hello, world
>>> print(2+3)
5
>>> print("2+3=", 2+3)
2+3= 5
>>>
The Magic of Python
 Usually we want to execute several
statements together that solve a
common problem. One way to do this is
to use a function.
 >>> def hello():
print("Hello")
print("Computers are Fun")
>>>
The Magic of Python
 >>> def hello():
print("Hello")
print("Computers are Fun")
>>>
 The first line tells Python we are defining a
new function called hello.
 The following lines are indented to show that
they are part of the hello function.
 The blank line (hit enter twice) lets Python
know the definition is finished.
The Magic of Python
 >>> def hello():
print("Hello")
print("Computers are Fun")
>>>
 Notice that nothing has happened yet! We’ve
defined the function, but we haven’t told
Python to perform the function!
 A function is invoked by typing its name.
 >>> hello()
Hello
Computers are Fun
>>>
The Magic of Python
 What’s the deal with the ()’s?
 Commands can have changeable parts
called parameters that are placed
between the ()’s.
 >>> def greet(person):
print("Hello",person)
print ("How are you?")
>>>
The Magic of Python
 >>> greet("Terry")
Hello Terry
How are you?
>>> greet("Paula")
Hello Paula
How are you?
>>>
 When we use parameters, we can
customize the output of our function.
The Magic of Python
 When we exit the Python prompt, the functions we’ve
defined cease to exist!
 Programs are usually composed of functions,
modules, or scripts that are saved on disk so that
they can be used again and again.
 A module file is a text file created in text editing
software (saved as “plain text”) that contains
function definitions.
 A programming environment is designed to help
programmers write programs and usually includes
automatic indenting, highlighting, etc.
The Magic of Python
# File: chaos.py
# A simple program illustrating chaotic behavior
def main():
print("This program illustrates a chaotic function")
x = eval(input("Enter a number between 0 and 1: "))
for i in range(10):
x = 3.9 * x * (1 - x)
print(x)
main()
 We’ll use filename.py when we save our work
to indicate it’s a Python program.
 In this code we’re defining a new function
called main.
 The main() at the end tells Python to run the
code.
Inside a Python Program
# File: chaos.py
# A simple program illustrating chaotic behavior
 Lines that start with # are called
comments
 Intended for human readers and
ignored by Python
 Python skips text from # to end of line
Inside a Python Program
def main():
 Beginning of the definition of a function
called main
 Since our program has only this one
module, it could have been written
without the main function.
 The use of main is customary, however.
Inside a Python Program
print("This program illustrates a chaotic function")
 This line causes Python to print a
message introducing the program.
Inside a Python Program
main()
 This last line tells Python to execute the
code in the function main
1. Write a program which prints the following information
about at least 5 persons:
`Full Name ‘ `Email-Address’ ` Telephone Number’
use print and println and see the difference.
Some Assignments 
Program, Assignment2
______
/ 
/ 
 /
______/
 /
______/
+--------+
______
/ 
/ 
| STOP |
 /
______/
______
/ 
/ 
+--------+
The structure of the output:
initial "egg" figure
second "teacup" figure
third "stop sign" figure
fourth "hat" figure
This structure can be represented by methods:
drawEgg
drawTeaCup
drawStopSign
drawHat
Program, Assignment3

More Related Content

Similar to Chapter01_Python.ppt

Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
natnaelmamuye
 
Notes1
Notes1Notes1
Notes1
hccit
 
Learn python
Learn pythonLearn python
Learn python
Rokibul Islam
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
CBJWorld
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
Sumit Satam
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
deepak kumbhar
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Syed Zaid Irshad
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
deepak teja
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
RamziFeghali
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
usvirat1805
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
Itzik Kotler
 
Built in function
Built in functionBuilt in function
Built in function
MD. Rayhanul Islam Sayket
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
Sumit Raj
 
Introduction to Python for Bioinformatics
Introduction to Python for BioinformaticsIntroduction to Python for Bioinformatics
Introduction to Python for Bioinformatics
José Héctor Gálvez
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
vishwanathgoudapatil1
 
Introduction to Declaring Functions in Python
Introduction to Declaring Functions in PythonIntroduction to Declaring Functions in Python
Introduction to Declaring Functions in Python
afsheenfaiq2
 
Class 1: Welcome to programming
Class 1: Welcome to programmingClass 1: Welcome to programming
Class 1: Welcome to programming
Marc Gouw
 
3 pagesPart 1Python comes with a program called an IDLE, wh.docx
3 pagesPart 1Python comes with a program called an IDLE, wh.docx3 pagesPart 1Python comes with a program called an IDLE, wh.docx
3 pagesPart 1Python comes with a program called an IDLE, wh.docx
domenicacullison
 
python presentation
python presentationpython presentation
python presentation
VaibhavMawal
 

Similar to Chapter01_Python.ppt (20)

Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Notes1
Notes1Notes1
Notes1
 
Learn python
Learn pythonLearn python
Learn python
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Built in function
Built in functionBuilt in function
Built in function
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Introduction to Python for Bioinformatics
Introduction to Python for BioinformaticsIntroduction to Python for Bioinformatics
Introduction to Python for Bioinformatics
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
 
Introduction to Declaring Functions in Python
Introduction to Declaring Functions in PythonIntroduction to Declaring Functions in Python
Introduction to Declaring Functions in Python
 
Class 1: Welcome to programming
Class 1: Welcome to programmingClass 1: Welcome to programming
Class 1: Welcome to programming
 
3 pagesPart 1Python comes with a program called an IDLE, wh.docx
3 pagesPart 1Python comes with a program called an IDLE, wh.docx3 pagesPart 1Python comes with a program called an IDLE, wh.docx
3 pagesPart 1Python comes with a program called an IDLE, wh.docx
 
python presentation
python presentationpython presentation
python presentation
 

More from PigPug1

Group 3 Tablet 126.pdf
Group 3 Tablet 126.pdfGroup 3 Tablet 126.pdf
Group 3 Tablet 126.pdf
PigPug1
 
Group 3(2)_1-l.pdf
Group 3(2)_1-l.pdfGroup 3(2)_1-l.pdf
Group 3(2)_1-l.pdf
PigPug1
 
mg annt ppt.pptx
mg annt ppt.pptxmg annt ppt.pptx
mg annt ppt.pptx
PigPug1
 
ILE126 Group 5 Presentation.pdf
ILE126 Group 5 Presentation.pdfILE126 Group 5 Presentation.pdf
ILE126 Group 5 Presentation.pdf
PigPug1
 
SMARTPHONE.pdf
SMARTPHONE.pdfSMARTPHONE.pdf
SMARTPHONE.pdf
PigPug1
 
1657506996803913.pptx
1657506996803913.pptx1657506996803913.pptx
1657506996803913.pptx
PigPug1
 
vnc.pptx
vnc.pptxvnc.pptx
vnc.pptx
PigPug1
 
VIC-4 Powerpoint.pptx
VIC-4 Powerpoint.pptxVIC-4 Powerpoint.pptx
VIC-4 Powerpoint.pptx
PigPug1
 
VIC-4 Powerpoint.pptx
VIC-4 Powerpoint.pptxVIC-4 Powerpoint.pptx
VIC-4 Powerpoint.pptx
PigPug1
 
vnc.pptx
vnc.pptxvnc.pptx
vnc.pptx
PigPug1
 
vnc_1660543731.pptx
vnc_1660543731.pptxvnc_1660543731.pptx
vnc_1660543731.pptx
PigPug1
 
vnc.pptx
vnc.pptxvnc.pptx
vnc.pptx
PigPug1
 
minii.pptx
minii.pptxminii.pptx
minii.pptx
PigPug1
 
PPT3.pptx
PPT3.pptxPPT3.pptx
PPT3.pptx
PigPug1
 
IRS151 Group 3 Presentation (1).pdf
IRS151 Group 3 Presentation (1).pdfIRS151 Group 3 Presentation (1).pdf
IRS151 Group 3 Presentation (1).pdf
PigPug1
 
GROUP3.pptx
GROUP3.pptxGROUP3.pptx
GROUP3.pptx
PigPug1
 
Ethics (U Tun Kyi).pdf
Ethics (U Tun Kyi).pdfEthics (U Tun Kyi).pdf
Ethics (U Tun Kyi).pdf
PigPug1
 
DESIGN OF MIXED MODE SOLAR CROP DRYER (_103848.pptx
DESIGN OF MIXED MODE SOLAR CROP DRYER (_103848.pptxDESIGN OF MIXED MODE SOLAR CROP DRYER (_103848.pptx
DESIGN OF MIXED MODE SOLAR CROP DRYER (_103848.pptx
PigPug1
 

More from PigPug1 (18)

Group 3 Tablet 126.pdf
Group 3 Tablet 126.pdfGroup 3 Tablet 126.pdf
Group 3 Tablet 126.pdf
 
Group 3(2)_1-l.pdf
Group 3(2)_1-l.pdfGroup 3(2)_1-l.pdf
Group 3(2)_1-l.pdf
 
mg annt ppt.pptx
mg annt ppt.pptxmg annt ppt.pptx
mg annt ppt.pptx
 
ILE126 Group 5 Presentation.pdf
ILE126 Group 5 Presentation.pdfILE126 Group 5 Presentation.pdf
ILE126 Group 5 Presentation.pdf
 
SMARTPHONE.pdf
SMARTPHONE.pdfSMARTPHONE.pdf
SMARTPHONE.pdf
 
1657506996803913.pptx
1657506996803913.pptx1657506996803913.pptx
1657506996803913.pptx
 
vnc.pptx
vnc.pptxvnc.pptx
vnc.pptx
 
VIC-4 Powerpoint.pptx
VIC-4 Powerpoint.pptxVIC-4 Powerpoint.pptx
VIC-4 Powerpoint.pptx
 
VIC-4 Powerpoint.pptx
VIC-4 Powerpoint.pptxVIC-4 Powerpoint.pptx
VIC-4 Powerpoint.pptx
 
vnc.pptx
vnc.pptxvnc.pptx
vnc.pptx
 
vnc_1660543731.pptx
vnc_1660543731.pptxvnc_1660543731.pptx
vnc_1660543731.pptx
 
vnc.pptx
vnc.pptxvnc.pptx
vnc.pptx
 
minii.pptx
minii.pptxminii.pptx
minii.pptx
 
PPT3.pptx
PPT3.pptxPPT3.pptx
PPT3.pptx
 
IRS151 Group 3 Presentation (1).pdf
IRS151 Group 3 Presentation (1).pdfIRS151 Group 3 Presentation (1).pdf
IRS151 Group 3 Presentation (1).pdf
 
GROUP3.pptx
GROUP3.pptxGROUP3.pptx
GROUP3.pptx
 
Ethics (U Tun Kyi).pdf
Ethics (U Tun Kyi).pdfEthics (U Tun Kyi).pdf
Ethics (U Tun Kyi).pdf
 
DESIGN OF MIXED MODE SOLAR CROP DRYER (_103848.pptx
DESIGN OF MIXED MODE SOLAR CROP DRYER (_103848.pptxDESIGN OF MIXED MODE SOLAR CROP DRYER (_103848.pptx
DESIGN OF MIXED MODE SOLAR CROP DRYER (_103848.pptx
 

Recently uploaded

一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
g4dpvqap0
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
AndrzejJarynowski
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
g4dpvqap0
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
kuntobimo2016
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
nuttdpt
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
ahzuo
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Enterprise Wired
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
nyfuhyz
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
nuttdpt
 

Recently uploaded (20)

一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
 

Chapter01_Python.ppt

  • 1. Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs
  • 2. The Magic of Python When you start Python, you will see something like: Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>>
  • 3. The Magic of Python  The “>>>” is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements.  >>> print("Hello, world“) Hello, world >>> print(2+3) 5 >>> print("2+3=", 2+3) 2+3= 5 >>>
  • 4. The Magic of Python  Usually we want to execute several statements together that solve a common problem. One way to do this is to use a function.  >>> def hello(): print("Hello") print("Computers are Fun") >>>
  • 5. The Magic of Python  >>> def hello(): print("Hello") print("Computers are Fun") >>>  The first line tells Python we are defining a new function called hello.  The following lines are indented to show that they are part of the hello function.  The blank line (hit enter twice) lets Python know the definition is finished.
  • 6. The Magic of Python  >>> def hello(): print("Hello") print("Computers are Fun") >>>  Notice that nothing has happened yet! We’ve defined the function, but we haven’t told Python to perform the function!  A function is invoked by typing its name.  >>> hello() Hello Computers are Fun >>>
  • 7. The Magic of Python  What’s the deal with the ()’s?  Commands can have changeable parts called parameters that are placed between the ()’s.  >>> def greet(person): print("Hello",person) print ("How are you?") >>>
  • 8. The Magic of Python  >>> greet("Terry") Hello Terry How are you? >>> greet("Paula") Hello Paula How are you? >>>  When we use parameters, we can customize the output of our function.
  • 9. The Magic of Python  When we exit the Python prompt, the functions we’ve defined cease to exist!  Programs are usually composed of functions, modules, or scripts that are saved on disk so that they can be used again and again.  A module file is a text file created in text editing software (saved as “plain text”) that contains function definitions.  A programming environment is designed to help programmers write programs and usually includes automatic indenting, highlighting, etc.
  • 10. The Magic of Python # File: chaos.py # A simple program illustrating chaotic behavior def main(): print("This program illustrates a chaotic function") x = eval(input("Enter a number between 0 and 1: ")) for i in range(10): x = 3.9 * x * (1 - x) print(x) main()  We’ll use filename.py when we save our work to indicate it’s a Python program.  In this code we’re defining a new function called main.  The main() at the end tells Python to run the code.
  • 11. Inside a Python Program # File: chaos.py # A simple program illustrating chaotic behavior  Lines that start with # are called comments  Intended for human readers and ignored by Python  Python skips text from # to end of line
  • 12. Inside a Python Program def main():  Beginning of the definition of a function called main  Since our program has only this one module, it could have been written without the main function.  The use of main is customary, however.
  • 13. Inside a Python Program print("This program illustrates a chaotic function")  This line causes Python to print a message introducing the program.
  • 14. Inside a Python Program main()  This last line tells Python to execute the code in the function main
  • 15. 1. Write a program which prints the following information about at least 5 persons: `Full Name ‘ `Email-Address’ ` Telephone Number’ use print and println and see the difference. Some Assignments 
  • 16. Program, Assignment2 ______ / / / ______/ / ______/ +--------+ ______ / / | STOP | / ______/ ______ / / +--------+ The structure of the output: initial "egg" figure second "teacup" figure third "stop sign" figure fourth "hat" figure This structure can be represented by methods: drawEgg drawTeaCup drawStopSign drawHat