Number generation function
# discussion http://codegolf.stackexchange.com/questions/35435/spell-out-numbers-in-french
# code from http://repl.it/WLD/2
def f(a):b=int(a/60)*10+10;d[a]=d[a-a%b]+(' et ','-')[a%10!=1or a>80]+d[a%b]
d=dict(zip([i for i in range(17)]+[i for i in range(20,70,10)]+[80,100],'zéro un deux trois quatre cinq six sept huit neuf dix onze douze treize quatorze quinze seize vingt trente quarante cinquante soixante quatre-vingt cent'.split()))
[f(v)for v in range(100)if(v in d)<1]
d[80]+='s'
# now d[] contains 0 to hundred
d[0] = ''
def get10(a):
return d[a]
def getNum(a,b):
m = ['', '', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf']
if 2 <= a <= 9:
return m[a] + ' ' + b + 's '
if 1 == a:
return b + ' '
return ' '
def get1000(a): return getNum(a,'mille') # mille doesn't have "s" actually...
def get100(a): return getNum(a,'cent')
French spelling of random numbers
random_French_number_generator
import random
for i in range(5):
m = [random.choice(range(3)), random.choice(range(10)), random.choice(range(100))]
mm = m[0] * 10 + m[1]
print(int(mm) if mm > 0 else '' , "{0:02d}".format(m[2]), ',', get1000(m[0]) + get100(m[1]) + get10(m[2]), sep='')
Result example
output
2752,deux milles sept cents cinquante-deux
1616,mille six cents seize
298, deux cents quatre-vingt-dix-huit
1658,mille six cents cinquante-huit
2138,deux milles cent trente-huit
Random price French spelling
random_French_prices_generator_in_Euros
for i in range(5):
m = [random.choice(range(100)), random.choice(range(100))]
print(m[0], '.', "{0:02d}".format(m[1]), ',', get10(m[0]) + (' euros ' if m[0] > 0 else '') + get10(m[1]) + (' centimes' if m[0] == 0 else ''), sep='')
Result example
output
19.15,dix-neuf euros quinze
32.33,trente-deux euros trente-trois
72.24,soixante-douze euros vingt-quatre
81.45,quatre-vingt-un euros quarante-cinq
52.48,cinquante-deux euros quarante-huit
Learning French.
https://quizlet.com/86236567/random-french-numbers-from-1-to-2999-flash-cards/
https://quizlet.com/86236880/random-french-price-numbers-in-euros-from-001e-to-9999e-flash-cards/
Recommended Posts