SlideShare a Scribd company logo
1.2 Basics of Python
1ARULKUMAR V AP/CSE - SECE
Motivations
Suppose, for example, that you need to take out a
student loan. Given the loan amount, loan term,
and annual interest rate, can you write a program
to compute the monthly payment and total
payment? This chapter shows you how to write
programs like this. Along the way, you learn the
basic steps that go into analyzing a problem,
designing a solution, and implementing the
solution by creating a program.
2ARULKUMAR V AP/CSE - SECE
Objectives
• To write programs that perform simple computations (§2.2).
• To obtain input from a program’s user by using the input function
(§2.3).
• To use identifiers to name variables (§2.4).
• To assign data to variables (§2.5).
• To define named constants (§2.6).
• To use the operators +, -, *, /, //, %, and ** (§2.7).
• To write and evaluate numeric expressions (§2.8).
• To use augmented assignment operators to simplify coding (§2.9).
• To perform numeric type conversion and rounding with the int and
round functions (§2.10).
• To obtain the current system time by using time.time() (§2.11).
• To describe the software development process and apply it to
develop the loan payment program (§2.12).
• To compute and display the distance between two points (§2.13).
3ARULKUMAR V AP/CSE - SECE
Introducing Programming with an
Example
Listing 2.1 Computing the Area of a
Circle
This program computes the area of
the circle.
4
ComputeArea
Run
IMPORTANT NOTE:
(1) To enable the buttons, you must download the entire 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 using
Office 2010, check PowerPoint2010.doc located in the
same folder with this ppt file.
ARULKUMAR V AP/CSE - SECE
Trace a Program Execution
# Assign a radius
radius = 20 # radius is now 20
# Compute area
area = radius * radius * 3.14159
# Display results
print("The area for the circle of radius " +
str(radius) + " is " + str(area))
5
20radius
Assign 20 to
radius
animation
ARULKUMAR V AP/CSE - SECE
Trace a Program Execution
# Assign a radius
radius = 20 # radius is now 20
# Compute area
area = radius * radius * 3.14159
# Display results
print("The area for the circle of radius“,
radius, " is "area)
6
20radius
Assign result to
area
animation
1256.636area
ARULKUMAR V AP/CSE - SECE
Trace a Program Execution
# Assign a radius
radius = 20 # radius is now 20
# Compute area
area = radius * radius * 3.14159
# Display results
print("The area for the circle of radius",
radius, "is", area)
7
20radius
print a message to
the console
animation
1256.636area
ARULKUMAR V AP/CSE - SECE
Reading Input from the Console
8
1. Use the input function
variable = input("Enter a string: ")
2. Use the eval function
var = eval(stringVariable)
eval("51 + (54 * (3 + 2))") returns 321.
ComputeAreaWithConsoleInput
Run
ComputeAverage
Run
ARULKUMAR V AP/CSE - SECE

More Related Content

Similar to 1. basics of python

Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Dr.Costas Sachpazis
 
Cw comp1640 211453_mo233_20131120_214054_1314
Cw comp1640 211453_mo233_20131120_214054_1314Cw comp1640 211453_mo233_20131120_214054_1314
Cw comp1640 211453_mo233_20131120_214054_1314
Owen Muzi
 
Biam 560 Enhance teaching / snaptutorial.com
Biam 560  Enhance teaching / snaptutorial.comBiam 560  Enhance teaching / snaptutorial.com
Biam 560 Enhance teaching / snaptutorial.com
HarrisGeorg45
 
Cmgt 410 cmgt410 cmgt 410 education for service uopstudy.com
Cmgt 410 cmgt410 cmgt 410 education for service   uopstudy.comCmgt 410 cmgt410 cmgt 410 education for service   uopstudy.com
Cmgt 410 cmgt410 cmgt 410 education for service uopstudy.com
UOPCourseHelp
 
Engineering C-programing module1 ppt (18CPS13/23)
Engineering C-programing module1 ppt (18CPS13/23)Engineering C-programing module1 ppt (18CPS13/23)
Engineering C-programing module1 ppt (18CPS13/23)
kavya R
 
Be cps-18 cps13or23-module1
Be cps-18 cps13or23-module1Be cps-18 cps13or23-module1
Be cps-18 cps13or23-module1
kavya R
 
© SAP SE CASE STUDY .docx
 © SAP SE   CASE STUDY .docx © SAP SE   CASE STUDY .docx
© SAP SE CASE STUDY .docx
mayank272369
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
solutionjug4
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6comp274
 
02slide_accessible.pptx
02slide_accessible.pptx02slide_accessible.pptx
02slide_accessible.pptx
MattMarino13
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical file
Ankit Dixit
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6helpido9
 
Primitive Data Types and Operations
Primitive Data Types and OperationsPrimitive Data Types and Operations
Primitive Data Types and Operations
naimanighat
 
Cis 498 Inspiring Innovation--tutorialrank.com
Cis 498  Inspiring Innovation--tutorialrank.comCis 498  Inspiring Innovation--tutorialrank.com
Cis 498 Inspiring Innovation--tutorialrank.com
PrescottLunt371
 
COCOMO methods for software size estimation
COCOMO methods for software size estimationCOCOMO methods for software size estimation
COCOMO methods for software size estimation
Pramod Parajuli
 
Unit3 overview of_c_programming
Unit3 overview of_c_programmingUnit3 overview of_c_programming
Unit3 overview of_c_programming
Capuchino HuiNing
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
jaymaraltamera
 
An Inter-Wiki Page Data Processor for a M2M System @Matsue, 1sep., Eskm2013
An Inter-Wiki Page Data Processor for a M2M System  @Matsue, 1sep., Eskm2013An Inter-Wiki Page Data Processor for a M2M System  @Matsue, 1sep., Eskm2013
An Inter-Wiki Page Data Processor for a M2M System @Matsue, 1sep., Eskm2013Takashi Yamanoue
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
KiranKumari204016
 

Similar to 1. basics of python (20)

Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Cw comp1640 211453_mo233_20131120_214054_1314
Cw comp1640 211453_mo233_20131120_214054_1314Cw comp1640 211453_mo233_20131120_214054_1314
Cw comp1640 211453_mo233_20131120_214054_1314
 
Biam 560 Enhance teaching / snaptutorial.com
Biam 560  Enhance teaching / snaptutorial.comBiam 560  Enhance teaching / snaptutorial.com
Biam 560 Enhance teaching / snaptutorial.com
 
Cmgt 410 cmgt410 cmgt 410 education for service uopstudy.com
Cmgt 410 cmgt410 cmgt 410 education for service   uopstudy.comCmgt 410 cmgt410 cmgt 410 education for service   uopstudy.com
Cmgt 410 cmgt410 cmgt 410 education for service uopstudy.com
 
Engineering C-programing module1 ppt (18CPS13/23)
Engineering C-programing module1 ppt (18CPS13/23)Engineering C-programing module1 ppt (18CPS13/23)
Engineering C-programing module1 ppt (18CPS13/23)
 
Be cps-18 cps13or23-module1
Be cps-18 cps13or23-module1Be cps-18 cps13or23-module1
Be cps-18 cps13or23-module1
 
LMmanual.pdf
LMmanual.pdfLMmanual.pdf
LMmanual.pdf
 
© SAP SE CASE STUDY .docx
 © SAP SE   CASE STUDY .docx © SAP SE   CASE STUDY .docx
© SAP SE CASE STUDY .docx
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
02slide_accessible.pptx
02slide_accessible.pptx02slide_accessible.pptx
02slide_accessible.pptx
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical file
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Primitive Data Types and Operations
Primitive Data Types and OperationsPrimitive Data Types and Operations
Primitive Data Types and Operations
 
Cis 498 Inspiring Innovation--tutorialrank.com
Cis 498  Inspiring Innovation--tutorialrank.comCis 498  Inspiring Innovation--tutorialrank.com
Cis 498 Inspiring Innovation--tutorialrank.com
 
COCOMO methods for software size estimation
COCOMO methods for software size estimationCOCOMO methods for software size estimation
COCOMO methods for software size estimation
 
Unit3 overview of_c_programming
Unit3 overview of_c_programmingUnit3 overview of_c_programming
Unit3 overview of_c_programming
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
 
An Inter-Wiki Page Data Processor for a M2M System @Matsue, 1sep., Eskm2013
An Inter-Wiki Page Data Processor for a M2M System  @Matsue, 1sep., Eskm2013An Inter-Wiki Page Data Processor for a M2M System  @Matsue, 1sep., Eskm2013
An Inter-Wiki Page Data Processor for a M2M System @Matsue, 1sep., Eskm2013
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
 

More from PhD Research Scholar

Ajax
AjaxAjax
Quiz servlet
Quiz servletQuiz servlet
Quiz servlet
PhD Research Scholar
 
Quiz
QuizQuiz
servlet db connectivity
servlet db connectivityservlet db connectivity
servlet db connectivity
PhD Research Scholar
 
2.java script dom
2.java script  dom2.java script  dom
2.java script dom
PhD Research Scholar
 
1.java script
1.java script1.java script
1.java script
PhD Research Scholar
 
Quiz javascript
Quiz javascriptQuiz javascript
Quiz javascript
PhD Research Scholar
 
Thread&multithread
Thread&multithreadThread&multithread
Thread&multithread
PhD Research Scholar
 
String
StringString
Streams&io
Streams&ioStreams&io
Streams&io
PhD Research Scholar
 
Packages
PackagesPackages
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
PhD Research Scholar
 
Inheritance
InheritanceInheritance
Exception handling
Exception handlingException handling
Exception handling
PhD Research Scholar
 
Applets
AppletsApplets
Abstract class
Abstract classAbstract class
Abstract class
PhD Research Scholar
 
7. tuples, set & dictionary
7. tuples, set & dictionary7. tuples, set & dictionary
7. tuples, set & dictionary
PhD Research Scholar
 
6. list
6. list6. list
5. string
5. string5. string

More from PhD Research Scholar (20)

Ajax
AjaxAjax
Ajax
 
Quiz servlet
Quiz servletQuiz servlet
Quiz servlet
 
Quiz
QuizQuiz
Quiz
 
servlet db connectivity
servlet db connectivityservlet db connectivity
servlet db connectivity
 
2.java script dom
2.java script  dom2.java script  dom
2.java script dom
 
1.java script
1.java script1.java script
1.java script
 
Quiz javascript
Quiz javascriptQuiz javascript
Quiz javascript
 
Thread&multithread
Thread&multithreadThread&multithread
Thread&multithread
 
String
StringString
String
 
Streams&io
Streams&ioStreams&io
Streams&io
 
Packages
PackagesPackages
Packages
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Inheritance
InheritanceInheritance
Inheritance
 
Exception handling
Exception handlingException handling
Exception handling
 
Applets
AppletsApplets
Applets
 
Abstract class
Abstract classAbstract class
Abstract class
 
7. tuples, set & dictionary
7. tuples, set & dictionary7. tuples, set & dictionary
7. tuples, set & dictionary
 
6. list
6. list6. list
6. list
 
5. string
5. string5. string
5. string
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

1. basics of python

  • 1. 1.2 Basics of Python 1ARULKUMAR V AP/CSE - SECE
  • 2. Motivations Suppose, for example, that you need to take out a student loan. Given the loan amount, loan term, and annual interest rate, can you write a program to compute the monthly payment and total payment? This chapter shows you how to write programs like this. Along the way, you learn the basic steps that go into analyzing a problem, designing a solution, and implementing the solution by creating a program. 2ARULKUMAR V AP/CSE - SECE
  • 3. Objectives • To write programs that perform simple computations (§2.2). • To obtain input from a program’s user by using the input function (§2.3). • To use identifiers to name variables (§2.4). • To assign data to variables (§2.5). • To define named constants (§2.6). • To use the operators +, -, *, /, //, %, and ** (§2.7). • To write and evaluate numeric expressions (§2.8). • To use augmented assignment operators to simplify coding (§2.9). • To perform numeric type conversion and rounding with the int and round functions (§2.10). • To obtain the current system time by using time.time() (§2.11). • To describe the software development process and apply it to develop the loan payment program (§2.12). • To compute and display the distance between two points (§2.13). 3ARULKUMAR V AP/CSE - SECE
  • 4. Introducing Programming with an Example Listing 2.1 Computing the Area of a Circle This program computes the area of the circle. 4 ComputeArea Run IMPORTANT NOTE: (1) To enable the buttons, you must download the entire 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 using Office 2010, check PowerPoint2010.doc located in the same folder with this ppt file. ARULKUMAR V AP/CSE - SECE
  • 5. Trace a Program Execution # Assign a radius radius = 20 # radius is now 20 # Compute area area = radius * radius * 3.14159 # Display results print("The area for the circle of radius " + str(radius) + " is " + str(area)) 5 20radius Assign 20 to radius animation ARULKUMAR V AP/CSE - SECE
  • 6. Trace a Program Execution # Assign a radius radius = 20 # radius is now 20 # Compute area area = radius * radius * 3.14159 # Display results print("The area for the circle of radius“, radius, " is "area) 6 20radius Assign result to area animation 1256.636area ARULKUMAR V AP/CSE - SECE
  • 7. Trace a Program Execution # Assign a radius radius = 20 # radius is now 20 # Compute area area = radius * radius * 3.14159 # Display results print("The area for the circle of radius", radius, "is", area) 7 20radius print a message to the console animation 1256.636area ARULKUMAR V AP/CSE - SECE
  • 8. Reading Input from the Console 8 1. Use the input function variable = input("Enter a string: ") 2. Use the eval function var = eval(stringVariable) eval("51 + (54 * (3 + 2))") returns 321. ComputeAreaWithConsoleInput Run ComputeAverage Run ARULKUMAR V AP/CSE - SECE