random French number generator with python

Basic definition

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')

create

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

What do you use it for?

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

random French number generator with python
Random number generator with normal distribution N (0,1)
Numpy random module random number generator
ABC161D Lunlun Number with python3
[python] Random number generation memorandum
Number recognition in images with Python
Testing with random numbers in Python
Infinite prime number generator in Python3
Realize PHP / Python generator with Golang / Ruby
FizzBuzz with Python3
Scraping with Python
Natural number generator
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
[Python] Generator function
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Stock number ranking by Qiita tag with python
Blender 2.8, Python, camera movement, random number color specification
Calculate the total number of combinations with python
I made a random number graph with Numpy
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Try scraping with Python.
Get corporate number at once via gbizinfo with python
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
[Note] Random number creation?
Kernel Method with Python
Scraping with Python + PhantomJS
Posting tweets with python
Drive WebDriver with python
Use mecab with Python3
[Python] Redirect with CGIHTTPServer