Here's my code:

metres = float(raw_input("Enter the height (in metres): "))
total_inches = 39.37 * metres
feet = int(total_inches/12)
inches = int(round(total_inches - feet*12))

if inches < 0.5:
    print "Sorry, you have entered a height that is less than 1/2 inches," \
          " please re-enter a new height."
elif feet < 1:
    print "It is" + " " + str(inches) + " inches high."

    print "It is" + " " + str(feet) + " feet," + " " + str(inches) + " inches high."

The output is something like

It is 4 feet, 6 inches high. (depends on your input)

How and what do I have to add to this code to turn the output into
It is four feet, six inches high.

So basically I want to know how to change the output into all words and no numbers.

Any help is appreciated. Also, please don't post any really hard coding because I just started python not long ago, so really complicated coding won't be of hel.

Thanks again!

8 Years
Discussion Span
Last Post by snippsat

Vegaseat has written a number to word converter.
But at dont see why you should need this.

#Let look at dictionary for som simple number to word stuff.
>>> d
{1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten'}
>>> dir(d)
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
>>> #now we can use dictionary method
>>> d.keys()
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> d.values()
['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
>>> d[1]
>>> d.has_key(4)
>>> d.has_key(12)
>>> #Noe let us convert number to word
>>> print 'Can you give my 1 in words,yes it is %s' % (d[1])
Can you give my 1 in words,yes it is one

Edited by snippsat: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.