I want solution for this question please

68 views
Skip to first unread message

mohamed

unread,
Sep 19, 2011, 4:54:59 PM9/19/11
to Building Skills Books
Check Amount Writing.
Translate a number into the English phrase.
This example algorithm fragment is only to get you started. This shows
how to pick off the digits from
the right end of a number and assemble a resulting string from the
left end of the string.
Note that the right-most two digits have special names, requiring some
additional cases above and
beyond the simplistic loop shown below. For example, 291 is “two
hundred ninety one”, where 29 is
“twenty nine”. The word for “2” changes, depending on the context.
As a practical matter, you should analyze the number by taking off
three digits at a time, the expression
‘(number % 1000)’ does this. You would then format the three digit
number with words like “million”,
“thousand”, etc.

Steven F. Lott

unread,
Sep 19, 2011, 5:51:24 PM9/19/11
to building-s...@googlegroups.com, Building Skills Books
It's better if you try to write this and then ask specific questions about your programming.

Giving an answer doesn't teach as much as discussing a partial or incomplete answer.

Sent from my iPhone

mohamed

unread,
Sep 20, 2011, 3:57:24 PM9/20/11
to Building Skills Books
but i'm understand this exercise how can translate number like 18 or
39
this code i have writing and i can't complete it

number = 3258
lenOfNumber = len(number)
tc = 0
result = ""
c = 0
while c <= lenOfNumber:


leftN = number1 % 10
if leftN == 1:
result += "One"
elif leftN == 2:
result += "Tow"
elif leftN == 3:
result += "Three"
elif leftN == 4:
result += "Four"
elif leftN == 5:
result += "Five"
if c == 0:
pass
elif c == 1 and leftN == 1:

Steven F. Lott

unread,
Sep 20, 2011, 9:04:33 PM9/20/11
to building-s...@googlegroups.com, Building Skills Books
From one to nineteen are all special cases. From twenty to ninety nine the cases are regular. "thirty" + " " + "eight".

You need a deeper if statement to separate 1-19 from 20-99.

Sent from my iPhone

Reply all
Reply to author
Forward
0 new messages