python:dierbach:chapter_1_python_first_steps
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python:dierbach:chapter_1_python_first_steps [2016/07/28 02:26] – [Using IDLE to develop a program] mithat | python:dierbach:chapter_1_python_first_steps [2016/07/28 04:26] (current) – [Document the solution] mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
~~SLIDESHOW~~ | ~~SLIDESHOW~~ | ||
+ | ~~NOTOC~~ | ||
====== Python first steps ====== | ====== Python first steps ====== | ||
Line 158: | Line 159: | ||
num_balloons = int(input(' | num_balloons = int(input(' | ||
</ | </ | ||
+ | |||
+ | ===== More about print() ===== | ||
+ | * You can print more than one thing with '' | ||
+ | * Separate each thing with a comma. | ||
+ | <code python> | ||
+ | >>> | ||
+ | >>> | ||
+ | There are 99 balloons | ||
+ | </ | ||
+ | * Each " | ||
===== A slightly more substantial program ===== | ===== A slightly more substantial program ===== | ||
Line 246: | Line 257: | ||
Oops (again). | Oops (again). | ||
- | ===== Code the solution (last time) ===== | + | ===== Code the solution (last time?) ===== |
<file python exponent_calculator.py> | <file python exponent_calculator.py> | ||
Line 267: | Line 278: | ||
</ | </ | ||
- | Success. | + | Success. But we can do better... |
+ | |||
+ | ===== Code the solution (last time!) ===== | ||
+ | |||
+ | <file python exponent_calculator.py> | ||
+ | # Exponent Calculator | ||
+ | # Exponent Calculator | ||
+ | # Calculate a base to an exponent' | ||
+ | # Mithat Konar | ||
+ | |||
+ | base = int(input(' | ||
+ | exponent = int(input(' | ||
+ | result = base ** exponent | ||
+ | print(base, 'to the power of', exponent, ' | ||
+ | </ | ||
+ | |||
+ | ===== Test the solution ===== | ||
+ | <code python> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | </ | ||
+ | |||
+ | The code is easier to read and it still works. | ||
===== Document the solution ===== | ===== Document the solution ===== | ||
Line 274: | Line 308: | ||
* Writing out details of the problem. | * Writing out details of the problem. | ||
* Writing out the design of the solution. | * Writing out the design of the solution. | ||
- | * Using comments in the source code. | + | * Writing |
* Do this. | * Do this. | ||
* **Every. Single. Time.** | * **Every. Single. Time.** | ||
python/dierbach/chapter_1_python_first_steps.1469672789.txt.gz · Last modified: 2016/07/28 02:26 by mithat