python:dierbach:chapter_1_python_first_steps

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
python:dierbach:chapter_1_python_first_steps [2016/07/28 02:26] – [Using IDLE to develop a program] mithatpython:dierbach:chapter_1_python_first_steps [2016/07/28 02:54] mithat
Line 158: Line 158:
 num_balloons = int(input('How many balloons? ')) num_balloons = int(input('How many balloons? '))
 </code> </code>
 +
 +===== More about print() =====
 +  * You can print more than one thing with ''print()''.
 +  * Separate each thing with a comma.
 +<code python>
 +>>> num = 99
 +>>> print("There are", num, "balloons.")
 +There are 99 balloons
 +</code>
 +* Each "thing" will be converted into a string.
  
 ===== A slightly more substantial program ===== ===== A slightly more substantial program =====
Line 246: Line 256:
 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 277:
 </code> </code>
  
-Success.+Success. But we can do better... 
 + 
 +Code the solution (last time!) 
 +------------------------------ 
 +<code python> 
 +# Exponent Calculator 
 +# Exponent Calculator 
 +# Calculate a base to an exponent's power. 
 +# Mithat Konar 
 + 
 +base = int(input('Enter the base: ')) 
 +exponent = int(input('Enter the exponent: ')) 
 +result = base ** exponent 
 +print(base, 'to the power of', exponent, 'is', result) 
 +</code> 
 + 
 +===== Test the solution ===== 
 +<code python> 
 +>>> Enter the base: 10 
 +>>> Enter the exponent: 4 
 +>>> 10 to the power of 4 is 10000 
 +</code> 
 + 
 +The code is easier to read and it still works
  
 ===== Document the solution ===== ===== Document the solution =====
python/dierbach/chapter_1_python_first_steps.txt · Last modified: 2016/07/28 04:26 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki