Introduction to Python ProgrammingXYZ Homework Edition

⇩ Download ▾

2.9 Chapter summary

Highlights from this chapter include:

At this point, you should be able to write programs that ask for input of mixed types, perform mathematical calculations, and output results with better formatting. The programming practice below ties together most topics presented in the chapter.

Table 2.10 Chapter 2 reference.
FunctionDescription
abs(x)Returns the absolute value of x.
int(x)Converts x (a string or float) to an integer.
float(x)Converts x (a string or integer) to a float.
str(x)Converts x (a float or integer) to a string.
round(x, ndigits)Rounds x to ndigits places after the decimal point. If ndigits is omitted, returns the nearest integer to x.
OperatorDescription
s * n
(Repetition)
Creates a string with n copies of s. Ex: "Ha" * 3 is "HaHaHa".
x / y
(Real division)
Divides x by y and returns the entire result as a float. Ex: 7 / 4 is 1.75.
x // y
(Floor division)
Divides x by y and returns the quotient as an integer. Ex: 7 // 4 is 1.
x % y
(Modulo)
Divides x by y and returns the remainder as an integer. Ex: 7 % 4 is 3.

Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.