12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /**
- * <https://y.st./>
- * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org./licenses/>.
- **/
- $xhtml = array(
- 'title' => 't_area.py',
- 'subtitle' => 'Written in <span title="Programming Fundamentals">CS 1101</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalized on 2017-02-08',
- 'copyright year' => '2017',
- 'body' => <<<END
- <img class="weblog-header-image" src="/img/CC_BY-SA_4.0/y.st./coursework/CS1101/t_area.py.png" alt="The output of the program is "96"." width="671" height="183" />
- <blockquote>
- <pre># Every good program should begin with a license comment that declares the file
- # as being covered by a free software license.
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org./licenses/>.
- # These are the dimentions of our triangle.
- base = 12
- height = 16
- # The formula specified by the assignment was this:
- #
- ## area = 1/2 * base * height
- #
- # However, Python uses integer division if both numbers are integers. Basically,
- # that means that:
- #
- ## 1 / 2 == 0
- #
- # It's the same as if you used this:
- #
- ## math.floor(1.0 / 2.0)
- #
- # We could modify the formula to use floating-point decimals instead of
- # integers, but that that would have the unintended effect of causing our
- # printed value to be a floating-point decimal. In many cases, that would be the
- # correct behaviour, but our answer is an integer. We might as well keep it as
- # an integer. Instead of changing the formula, we could also use:
- #
- ## from __future__ import division
- #
- # Again though, this would have the effect of changing our printed integer into
- # a floating-point decimal.
- area = base * height / 2
- # If we'd acquired a floating-point answer instead of an integer answer, we'd
- # see ".0" appended to the answer when we printed it.
- print area
- </pre>
- </blockquote>
- END
- );
|