[Python-checkins] CVS: python/dist/src/Doc/tut tut.tex,1.100.2.5,1.100.2.6

Fred L. Drake fdrake@weyr.cnri.reston.va.us
Tue, 22 Feb 2000 12:26:05 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Doc/tut
In directory weyr:/home/fdrake/projects/python/Doc-152p1/tut

Modified Files:
      Tag: release152p1-patches
	tut.tex 
Log Message:

Adjust the examples starting the "if Statement" and "Handling
Exceptions" based on comments from Peter Funk <pf@artcom-gmbh.de>;
these should be more "approachable" for novice programmers.


Index: tut.tex
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.100.2.5
retrieving revision 1.100.2.6
diff -C2 -r1.100.2.5 -r1.100.2.6
*** tut.tex	2000/02/22 04:34:28	1.100.2.5
--- tut.tex	2000/02/22 17:26:02	1.100.2.6
***************
*** 913,918 ****
  
  \begin{verbatim}
! >>> import random
! >>> x = random.choice([-1, 0, 1, 2])
  >>> if x < 0:
  ...      x = 0
--- 913,917 ----
  
  \begin{verbatim}
! >>> x = int(raw_input("Please enter a number: "))
  >>> if x < 0:
  ...      x = 0
***************
*** 2747,2766 ****
  
  It is possible to write programs that handle selected exceptions.
! Look at the following example, which prints a table of inverses of
! some floating point numbers:
  
  \begin{verbatim}
! >>> numbers = [0.3333, 2.5, 0, 10]
! >>> for x in numbers:
! ...     print x,
  ...     try:
! ...         print 1.0 / x
! ...     except ZeroDivisionError:
! ...         print '*** has no inverse ***'
  ...     
- 0.3333 3.00030003
- 2.5 0.4
- 0 *** has no inverse ***
- 10 0.1
  \end{verbatim}
  
--- 2746,2763 ----
  
  It is possible to write programs that handle selected exceptions.
! Look at the following example, which asks the user for input until a
! valid integer has been entered, but allows the user to interrupt the
! program (using \kbd{Control-C} or whatever the operating system
! supports); note that a user-generated interruption is signalled by
! raising the \exception{KeyboardInterrupt} exception.
  
  \begin{verbatim}
! >>> while 1:
  ...     try:
! ...         x = int(raw_input("Please enter a number: "))
! ...         break
! ...     except ValueError:
! ...         print "Oops! That was no valid number.  Try again..."
  ...     
  \end{verbatim}