This is the summary for YOU, if you want to learn the basics of Python quickly.
Not everyone has time to read a book of more than 200 pages.
That's why I thought, why don't I make a short summary of it!
This is a summary of chapter 5 of the book ThinkPython2 (with the exercises!).
I can't summari...
The main topic of this chapter is the if statement, which executes different code depending on the
state of the program. But first two new operators are introduced: floor division and modulus.
5.1 Floor division and modulus
The floor division operator (//) divides 2 integers and round down to an integer. Suppose a movie
is 105 minutes. You want to know how many hours that is. A division returns a floating point:
>>> minutes = 105 1.75
>>> minutes / 60
But you want to know it in an integer. Floor division returns the hours in integer, rounding down:
>>> minutes = 105 1
>>> hours = minutes // 60
>>> hours
To get the remainder you use modulus (%) which divides 2 numbers and returns the remainder:
>>> remainder = minutes % 60 45
>>> remainder
You could also use this to check whether a number is divisible by another: if x % y is 0, then x is
divisible by y. Or you could extract the right most digit(s) from a number: x % 10 yields the right-
most digit of x (in base 10). Similarly x % 100 yields the last two digits.
5.2 Boolean expressions
The benefits of buying summaries with Stuvia:
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
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
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 these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Yuna429. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $3.26. You're not tied to anything after your purchase.