06.09.2021 Views

How to Think Like a Computer Scientist - Learning with Python, 2008a

How to Think Like a Computer Scientist - Learning with Python, 2008a

How to Think Like a Computer Scientist - Learning with Python, 2008a

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

42 Conditionals and recursion<br />

if 0 < x < 10:<br />

print "x is a positive single digit."<br />

This condition is semantically the same as the compound boolean expression and<br />

the nested conditional.<br />

4.8 The return statement<br />

The return statement allows you <strong>to</strong> terminate the execution of a function before<br />

you reach the end. One reason <strong>to</strong> use it is if you detect an error condition:<br />

import math<br />

def printLogarithm(x):<br />

if x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!