Re: converting numbers into words

2017-11-09 Thread Grant Edwards
On 2017-11-09, r161...@rguktrkv.ac.in  wrote:

> How can I covert numbers into word like ex:-123 One hundred twenty three?

That's one of the classic freshman intro-to-programming homework
problems.  I remember having to write a Pascal program to do that back
in the 70's...

-- 
Grant Edwards   grant.b.edwardsYow! Are we laid back yet?
  at   
  gmail.com

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: converting numbers into words (Posting On Python-List Prohibited)

2017-11-09 Thread Christopher Reimer
On Nov 9, 2017, at 3:45 AM, John Ladasky  wrote:
> 
>> On Wednesday, November 8, 2017 at 11:40:18 PM UTC-8, Lawrence D’Oliveiro 
>> wrote:
>>> On Thursday, November 9, 2017 at 7:51:35 PM UTC+13, r16...@rguktrkv.ac.in 
>>> wrote:
>>> 
>>> How can I covert numbers into word like ex:-123 One hundred twenty three?
>> 
>> Here’s  one I 
>> did earlier, in Algol 68.
>> 
>> Conversion to Python is left as an exercise for the reader.
> 
> I think that gives away rather more than I wanted the student to see.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

I thought the classic homework problem was to convert an Arabic numeral into a 
Roman numeral. Bonus points for correctly converting any number above 12 and/or 
copyright year from any old movie. Most students have seen Roman numerals on 
clocks (1-12).

Maybe that's too hard for today's kids with digital clocks.

Chris R.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: converting numbers into words

2017-11-09 Thread bartc

On 09/11/2017 06:51, r161...@rguktrkv.ac.in wrote:

How can I covert numbers into word like ex:-123 One hundred twenty three?



google for something like "algorithm numbers to words".

If this is homework, then it's not cheating as everyone else will be 
doing the same.


> How can I covert numbers into word like ex:-123 One hundred twenty three?

And you need to refine your specification of the task. I would render 
your example as:


 minus one hundred and twenty-three




--
https://mail.python.org/mailman/listinfo/python-list


Re: converting numbers into words (Posting On Python-List Prohibited)

2017-11-09 Thread John Ladasky
On Wednesday, November 8, 2017 at 11:40:18 PM UTC-8, Lawrence D’Oliveiro wrote:
> On Thursday, November 9, 2017 at 7:51:35 PM UTC+13, r16...@rguktrkv.ac.in 
> wrote:
> 
> > How can I covert numbers into word like ex:-123 One hundred twenty three?
> 
> Here’s  one I 
> did earlier, in Algol 68.
> 
> Conversion to Python is left as an exercise for the reader.

I think that gives away rather more than I wanted the student to see.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: converting numbers into words

2017-11-08 Thread jladasky
On Wednesday, November 8, 2017 at 10:51:35 PM UTC-8, r16...@rguktrkv.ac.in 
wrote:
> How can I covert numbers into word like ex:-123 One hundred twenty three?

That's a classic homework exercise.  Expect guidance, not an answer.

Why don't you solve a related, but simpler task first?  This is a good approach 
to learning computer programming.  Write a program that accepts a single digit 
as input, and outputs the corresponding word.  Post the code here.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Converting numbers to words

2009-02-05 Thread Steve Holden
todp...@hotmail.com wrote:
 I've been trying to figure this out for over 2 hours and I'm really
 frustrated right now.
 
 I first made Python to ask user to input height in meters. If user puts
 certain value in meter, then it converts it to feet and inches as follows:
  
 
 Enter the height (in metres): 1.6
 
 It is 5 feet, 3 inches high.
  
  
 What I want to do is to make it type only words. For example, instead of
 its saying, It is 5 feet, 3 inches high, I want it to say, it is five
 feet, three inches high.
 I'd appreciate any suggestions.

Create a list or tuple of strings, and use the numbers to index the list.

lst = ['a', 'b', 'c']
ndx = 1
print The letter, lst[ndx], is number one

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting numbers to words

2009-02-05 Thread Brian Allen Vanderburg II

todp...@hotmail.com wrote:

 I've been trying to figure this out for over 2 hours and I'm really 
frustrated right now.


 I first made Python to ask user to input height in meters. If user 
puts certain value in meter, then it converts it to feet and inches as 
follows:
  


 Enter the height (in metres): 1.6

 It is 5 feet, 3 inches high.
  
  
 What I want to do is to make it type only words. For example, instead 
of its saying, It is 5 feet, 3 inches high, I want it to say, it is 
five feet, three inches high.

 I'd appreciate any suggestions.

I made something similar in the past.  First I break it into two 
functions, one function handles 0-999 and return '' for zero or a 
meaningful value for 999, another function handles how many groups there 
are and for each one, gets the value for it calls the first function, 
and appends the correct word.  This only works for the English language 
though


Brian Vanderburg II

num_words1 = (zero, # not used
one,
two,
three,
four,
five,
six,
seven,
eight,
nine,
ten,
eleven,
twelve,
thirteen,
fourteen,
fifteen,
sixteen,
seventeen,
eighteen,
nineteen)

num_words2 = (twenty,
thirty,
forty,
fifty,
sixty,
seventy,
eighty,
ninety)

num_words3 = (thousand,
million,
billion,
trillion,
quadrillion)

def word_func1(value):
  # value can be from 0 to 999
  result = ''

  if value == 0:
  return result

  # Handle hundreds
  if value = 100:
  hvalue = int(value / 100)
  if result:
  result += ' '
  result += num_words1[hvalue]
  result += ' hundred'
  value -= (hvalue * 100)

  if value == 0:
  return result

  # Handle 1-19
  if value  20:
  if result:
  result += ' '
  result += num_words1[value]
  return result

  # Handle 10s (20-90)
  tvalue = int(value / 10)
  if result:
  result += ' '
  result += num_words2[tvalue - 2]
  value -= (tvalue * 10)

  if value == 0:
  return result

  # Handle ones
  if result:
  result += ' '
  result += num_words1[value]

  return result

def word_func2(value):
  result = ''

  if value == 0:
  return 'zero'

  # Determine support values
  divider = 1
  l = len(num_words3)
  for i in range(l):
  divider *= 1000

  for i in range(l):
  if value = divider:
  dvalue = int(value / divider)
  if result:
  result += ' '
  result += word_func1(dvalue)
  result += ' '
  result += num_words3[l - i - 1]
  value -= (dvalue * divider)
  divider /= 1000

  if value  0:
  if result:
  result += ' '
  result += word_func1(value)

  return result

number_to_word = word_func2

--
http://mail.python.org/mailman/listinfo/python-list