[Tutor] Projects

Jason Massey jason.massey at gmail.com
Wed Jan 23 15:20:11 CET 2008


On Jan 22, 2008 5:10 PM, Damian Archer <imonthejazz at googlemail.com> wrote:

>   So anyone have any good project ideas, perhaps projects that people have
> undertaken before??
>
>

I'm taking a Java class this semester and our first program is a number
translator.  Here's the assignment:

*Below is a sample run:*

  Welcome to my number translator!

  Enter amount [0-999999.99; 0 to exit]: 1234.56
  Translation: one thousand two hundred thirty-four and 56/100



  Enter amount [0-999999.99; 0 to exit]: 17775
  Translation: seventeen thousand seven hundred seventy-five and 00/100


  Enter amount [0-999999.99; 0 to exit]: -45
  Enter amount [0-999999.99; 0 to exit]: 999999999.99

  Enter amount [0-999999.99; 0 to exit]: 22.95
  Translation: twenty-two and 95/100


  Enter amount [0-999999.99; 0 to exit]: 0.01
  Translation: zero and 01/100


  Enter amount [0-999999.99; 0 to exit]: 909909.99
  Translation: nine hundred nine thousand nine hundred nine and 99/100


  Enter amount [0-999999.99; 0 to exit]: 0
  Bye bye!

*Input*

You may assume that your input is in floating point format (no dollar signs
or commas or other special characters other than a single decimal point).  But
you will need to check to make sure your input satisfies the specs given
above.  (Although with exception handling it's not difficult to validate
that you have floating point format.)
---

An example routine to translate a number into it's english equivalent was
given (again, this is Java):
  static String convertDigitToEnglish(int d)  {
      switch ( d )
      {

         case 1: return "one";
         case 2: return "two";
         case 3: return "three";
         case 4: return "four";
         case 5: return "five";
         case 6: return "six";
         case 7: return "seven";
         case 8: return "eight";
         case 9: return "nine";
         default: return "\nFatal Error!\n"; // should I abort pgm?
      } // end of switch
  } // end of convertDigitToEnglish

In Python I'd just use a dictionary.

HTH,

jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080123/d277d350/attachment.htm 


More information about the Tutor mailing list