100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Python textbook. R293,00   Add to cart

Class notes

Python textbook.

 3 views  0 purchase

The explanation about python

Preview 4 out of 283  pages

  • August 5, 2022
  • 283
  • 2022/2023
  • Class notes
  • Professor ntuli
  • All classes
book image

Book Title:

Author(s):

  • Edition:
  • ISBN:
  • Edition:
All documents for this subject (7)
avatar-seller
ngxinjanaazille
LEARNING TO PROGRAM WITH PYTHON




Richard L. Halterman

,Copyright © 2011 Richard L. Halterman. All rights reserved.

, i




Contents


1 The Context of Software Development 1
1.1 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Development Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Learning Programming with Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Writing a Python Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 A Longer Python program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2 Values and Variables 11
2.1 Integer Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Variables and Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.4 Floating-point Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.5 Control Codes within Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.6 User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.7 The eval Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.8 Controlling the print Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3 Expressions and Arithmetic 35
3.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.2 Operator Precedence and Associativity . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.3 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.4 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

©2011 Richard L. Halterman Draft date: November 13, 2011

, CONTENTS ii


3.4.1 Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.4.2 Run-time Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.4.3 Logic Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.5 Arithmetic Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3.6 More Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.7 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
3.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4 Conditional Execution 57
4.1 Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.2 Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.3 The Simple if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.4 The if/else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.5 Compound Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.6 Nested Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.7 Multi-way Decision Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.8 Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.9 Errors in Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

5 Iteration 81
5.1 The while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.2 Definite Loops vs. Indefinite Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.3 The for Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.4 Nested Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.5 Abnormal Loop Termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
5.5.1 The break statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
5.5.2 The continue Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
5.6 Infinite Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
5.7 Iteration Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
5.7.1 Computing Square Root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5.7.2 Drawing a Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
5.7.3 Printing Prime Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

©2011 Richard L. Halterman Draft date: November 13, 2011

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller ngxinjanaazille. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for R293,00. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67474 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Start selling
R293,00
  • (0)
  Buy now