## Witamy!

You are in Poland and want to order a drink. You need to ask "One beer please": "Jedno piwo poprosze"

``` java
Translator.orderingBeers(1) = "Jedno piwo poprosze"
```

But let's say you are really thirsty and want several beers. Then you need to count in Polish. And more difficult, you need to understand the Polish grammar and cases (nominative, genitive, accustative and more).

## The grammar

In English, the plural of "beer" is simply "beers", with an "s". 

In Polish, the plural of "piwo" (nominative singular) is "piw" (genitive plural) or "piwa" (nominative plural). It depends!


The rules:

* usually the plural is genitive: "piw"
* but after the numerals 2, 3, 4, and compound numbers ending with them (e.g. 22, 23, 24), the noun is plural and takes the same case as the numeral, so nominative: "piwa"
* and exception to the exception: for 12, 13 and 14, it's the genitive plural again: "piw" (yes, I know, it's crazy!)


## The numbers

From 0 to 9:
    
    "zero", "jeden", "dwa", "trzy", "cztery", "piec", "szesc" , "siedem", "osiem", "dziewiec"

From 10 to 19 it's nearly the same, with "-ascie" at the end:

    "dziesiec", "jedenascie", "dwanascie", "trzynascie", "czternascie", "pietnascie", "szesnascie", "siedemnascie", "osiemnascie", "dziewietnascie"

Tens from 10 to 90 are nearly the same, with "-ziesci" or "ziesiat" at the end:

    "dziesiec", "dwadziescia", "trzydziesci", "czterdziesci", "piecdziesiat", "szescdziesiat", "siedemdziesiat", "osiemdziesiat", "dziewiecdziesiat"

Compound numbers are constructed similarly to English: tens + units. For example, 22 is "dwadziescia dwa".

"One" could be male ("Jeden"), female ("Jedna") or neuter ("Jedno"), which is the case for "beer" (piwo). But all other numbers are invariant, even if ending with "jeden".

Ah, and by the way, if you don't want to drink alcohol (so no beers are ordered), ask for mineral water instead: "Woda mineralna".

Note: if the number of beers is outside your (limited) Polish knowledge (0-99), raise an error!

---
More about the crazy polish grammar: https://en.wikipedia.org/wiki/Polish_grammar

Difficulty: EASY
Starter code: def ordering_beers(beers):
	

Solutions:
def ordering_beers(beers):
	assert 0 <= beers < 100
	units = ['', 'jeden', 'dwa', 'trzy', 'cztery', 'piec', 'szesc', 'siedem', 'osiem', 'dziewiec', 'dziesiec', 'jedenascie', 'dwanascie', 'trzynascie', 'czternascie', 'pietnascie', 'szesnascie', 'siedemnascie', 'osiemnascie', 'dziewietnascie']
	tens = ['', '', 'dwadziescia', 'trzydziesci', 'czterdziesci', 'piecdziesiat', 'szescdziesiat', 'siedemdziesiat', 'osiemdziesiat', 'dziewiecdziesiat']
	if beers == 0:
		order = 'Woda mineralna'
	elif beers == 1:
		order = 'Jedno piwo'
	elif beers < 20:
		order = units[beers] + ' piw'
	else:
		order = tens[beers // 10] + ' ' * bool(beers % 10) + units[beers % 10] + ' piw'
	if beers % 10 in [2, 3, 4] and beers not in [12, 13, 14]:
		order += 'a'
	return order.capitalize() + ' poprosze'


def ordering_beers(beers):
	one_to_ten = {1: 'jeden', 2: 'dwa', 3: 'trzy', 4: 'cztery', 5: 'piec', 6: 'szesc', 7: 'siedem', 8: 'osiem', 9: 'dziewiec'}
	ten_to_nineteen = {10: 'dziesiec', 11: 'jedenascie', 12: 'dwanascie', 13: 'trzynascie', 14: 'czternascie', 15: 'pietnascie', 16: 'szesnascie', 17: 'siedemnascie', 18: 'osiemnascie', 19: 'dziewietnascie'}
	twenty_to_ninety = {20: 'dwadziescia', 30: 'trzydziesci', 40: 'czterdziesci', 50: 'piecdziesiat', 60: 'szescdziesiat', 70: 'siedemdziesiat', 80: 'osiemdziesiat', 90: 'dziewiecdziesiat'}
	if 99 > beers < 0:
		raise Exception()
	if beers == 0:
		return 'Woda mineralna poprosze'
	else:
		beers_str = list(str(beers))
		piwa = [2, 3, 4]
		if len(beers_str) > 1:
			if 10 <= beers <= 19:
				return ten_to_nineteen[beers].capitalize() + ' piw poprosze'
			if beers >= 20:
				result = twenty_to_ninety[int(beers_str[0] + '0')].capitalize()
				return result + ' piw poprosze' if beers_str[1] == '0' else result + ' ' + one_to_ten[int(beers_str[1])] + ' piwa poprosze' if int(beers_str[1]) in piwa else result + ' ' + one_to_ten[int(beers_str[1])] + ' piw poprosze'
		else:
			ones = one_to_ten[int(beers_str[0])]
			return 'Jedno piwo poprosze' if beers == 1 else str(ones).capitalize() + ' piwa poprosze' if beers in piwa else str(ones).capitalize() + ' piw poprosze'


ones = {0: 'Woda', 1: 'Jeden', 2: 'dwa', 3: 'trzy', 4: 'cztery', 5: 'piec', 6: 'szesc', 7: 'siedem', 8: 'osiem', 9: 'dziewiec'}
twos = {10: 'dziesiec', 11: 'jedenascie', 12: 'dwanascie', 13: 'trzynascie', 14: 'czternascie', 15: 'pietnascie', 16: 'szesnascie', 17: 'siedemnascie', 18: 'osiemnascie', 19: 'dziewietnascie'}
tens = {10: 'dziesiec', 20: 'dwadziescia', 30: 'trzydziesci', 40: 'czterdziesci', 50: 'piecdziesiat', 60: 'szescdziesiat', 70: 'siedemdziesiat', 80: 'osiemdziesiat', 90: 'dziewiecdziesiat'}
ordering_beers = lambda n: [ones.get(n, twos.get(n, tens.get(n, tens[(n // 10 or 1) * 10] + ' ' + ones[n % 10]))), 'Jedno'][n == 1].capitalize() + ' ' + ['mineralna', ['piwo', ['piw', 'piwa'][n in [2, 3, 4] or (n // 10 in [2, 3, 4] and n % 10 in [2, 3, 4])]][n != 1]][n != 0] + ' ' + 'poprosze'


UNITS = ' jeden dwa trzy cztery piec szesc siedem osiem dziewiec'.split(' ')
TENS = 'dziesiec jedenascie dwanascie trzynascie czternascie pietnascie szesnascie siedemnascie osiemnascie dziewietnascie'.split(' ')
TENTH = '  dwadziescia trzydziesci czterdziesci piecdziesiat szescdziesiat siedemdziesiat osiemdziesiat dziewiecdziesiat'.split(' ')

def ordering_beers(n):
	if not 0 <= n < 100:
		raise ValueError('Nie wiem')
	(t, u) = divmod(n, 10)
	number = {0: UNITS[u], 1: TENS[u]}.get(t, TENTH[t] + ' ' * (u > 0) + UNITS[u])
	plural = 'piwa' if t != 1 and 1 < u < 5 else 'piw'
	order = {0: 'woda mineralna', 1: 'jedno piwo'}.get(n, number + ' ' + plural)
	return '{} poprosze'.format(order).capitalize()


def ordering_beers(beers):
	assert 0 <= beers < 100
	units = ['', 'jeden', 'dwa', 'trzy', 'cztery', 'piec', 'szesc', 'siedem', 'osiem', 'dziewiec', 'dziesiec', 'jedenascie', 'dwanascie', 'trzynascie', 'czternascie', 'pietnascie', 'szesnascie', 'siedemnascie', 'osiemnascie', 'dziewietnascie']
	tens = ['dwadziescia', 'trzydziesci', 'czterdziesci', 'piecdziesiat', 'szescdziesiat', 'siedemdziesiat', 'osiemdziesiat', 'dziewiecdziesiat']
	order = ['Woda mineralna', 'Jedno piwo']
	for (i, num) in enumerate(units[2:], 2):
		order.append('%s piw%s' % (num, 'a' if i in [2, 3, 4] else ''))
	for n in tens:
		for i in range(10):
			order.append('%s%s%s piw%s' % (n, ' ' * bool(i), units[i], 'a' if i in [2, 3, 4] else ''))
	return order[beers].capitalize() + ' poprosze'


singleNums = ['zero', 'jeden', 'dwa', 'trzy', 'cztery', 'piec', 'szesc', 'siedem', 'osiem', 'dziewiec']
tenth = ['dziesiec', 'jedenascie', 'dwanascie', 'trzynascie', 'czternascie', 'pietnascie', 'szesnascie', 'siedemnascie', 'osiemnascie', 'dziewietnascie']
tens = ['dziesiec', 'dwadziescia', 'trzydziesci', 'czterdziesci', 'piecdziesiat', 'szescdziesiat', 'siedemdziesiat', 'osiemdziesiat', 'dziewiecdziesiat']

def ordering_beers(beers):
	if beers < 0:
		raise ValueError('No negative values')
	elif beers < 1:
		return 'Woda mineralna poprosze'
	elif beers == 1:
		return 'Jedno piwo poprosze'
	whole = beers // 10
	modulo = beers % 10
	if beers > 10 and beers < 15:
		noun = 'piw'
	elif modulo > 1 and modulo < 5:
		noun = 'piwa'
	else:
		noun = 'piw'
	if beers < 10:
		numeral = singleNums[beers]
	elif beers > 9 and beers < 20:
		numeral = tenth[modulo]
	elif modulo == 0 and beers > 19:
		numeral = tens[whole - 1]
	else:
		numeral = tens[whole - 1] + ' ' + singleNums[modulo]
	return numeral.capitalize() + ' ' + noun + ' poprosze'


ones = ['jeden', 'dwa', 'trzy', 'cztery', 'piec', 'szesc', 'siedem', 'osiem', 'dziewiec']
teens = ['dziesiec', 'jedenascie', 'dwanascie', 'trzynascie', 'czternascie', 'pietnascie', 'szesnascie', 'siedemnascie', 'osiemnascie', 'dziewietnascie']
tens = ['dziesiec', 'dwadziescia', 'trzydziesci', 'czterdziesci', 'piecdziesiat', 'szescdziesiat', 'siedemdziesiat', 'osiemdziesiat', 'dziewiecdziesiat']

def ordering_beers(beers):
	if beers < 0:
		raise 'No negative beers'
	if not beers:
		return 'Woda mineralna poprosze'
	output = ''
	ending = 'o' if beers == 1 else 'a' if beers % 10 in (2, 3, 4) and (not beers in (12, 13, 14)) else ''
	if beers > 19:
		output = tens[beers // 10 - 1]
		beers %= 10
	elif beers > 9:
		output = teens[beers - 10]
		beers = 0
	if beers:
		if output:
			output += ' '
		output += 'jedno' if beers == 1 and (not ' ' in output) else ones[beers - 1]
	return f'{output} piw{ending} poprosze'.capitalize()


def ordering_beers(beers):
	oneToTwenty = ['zero', 'jeden', 'dwa', 'trzy', 'cztery', 'piec', 'szesc', 'siedem', 'osiem', 'dziewiec', 'dziesiec', 'jedenascie', 'dwanascie', 'trzynascie', 'czternascie', 'pietnascie', 'szesnascie', 'siedemnascie', 'osiemnascie', 'dziewietnasce', 'dwadziescia']
	tens = ['dziesiec', 'dwadziescia', 'trzydziesci', 'czterdziesci', 'piecdziesiat', 'szescdziesiat', 'siedemdziesiat', 'osiemdziesiat', 'dziewiecdziesiat']
	if beers < 0:
		raise Exception('Only positive numbers!')
	elif beers == 0:
		return 'Woda mineralna poprosze'
	elif beers == 1:
		return 'Jedno piwo poprosze'
	elif beers <= 20:
		order = oneToTwenty[beers]
		order = order[:1].upper() + order[1:]
	else:
		order = tens[int(beers / 10) - 1] + ' ' + oneToTwenty[beers % 10]
		order = order[:1].upper() + order[1:]
	if beers in [12, 13, 14]:
		order = order + ' piw'
	elif beers % 10 in [2, 3, 4]:
		order = order + ' piwa'
	else:
		order = order + ' piw'
	return order + ' poprosze'


dict_units = {0: 'Woda', 1: 'jeden', 2: 'dwa', 3: 'trzy', 4: 'cztery', 5: 'piec', 6: 'szesc', 7: 'siedem', 8: 'osiem', 9: 'dziewiec'}
dict_units_1 = {10: 'dziesiec', 11: 'jedenascie', 12: 'dwanascie', 13: 'trzynascie', 14: 'czternascie', 15: 'pietnascie', 16: 'szesnascie', 17: 'siedemnascie', 18: 'osiemnascie', 19: 'dziewietnascie'}
dict_dec = {10: 'dziesiec', 20: 'dwadziescia', 30: 'trzydziesci', 40: 'czterdziesci', 50: 'piecdziesiat', 60: 'szescdziesiat', 70: 'siedemdziesiat', 80: 'osiemdziesiat', 90: 'dziewiecdziesiat'}

def ordering_beers(beers):
	if beers > 99:
		raise Exception
	length = len(str(beers))
	digit_l = None
	digit_r = None
	beer_word = None
	please = 'poprosze'
	if length > 1:
		if beers in [10, 20, 30, 40, 50, 60, 70, 80, 90]:
			return '{} {} {}'.format(dict_dec[beers].capitalize(), 'piw', please)
		elif beers in [11, 12, 13, 14, 15, 16, 17, 18, 19]:
			return '{} {} {}'.format(dict_units_1[beers].capitalize(), 'piw', please)
		digit_l = int(str(beers)[0])
		digit_r = int(str(beers)[1])
		if digit_r in [2, 3, 4]:
			beer_word = 'piwa'
		elif digit_r == 1:
			beer_word = 'piw'
		elif digit_r == 0:
			beer_word = 'mineralna'
		else:
			beer_word = 'piw'
		return '{} {} {} {}'.format(dict_dec[digit_l * 10].capitalize(), dict_units[digit_r], beer_word, please)
	else:
		digit_r = int(beers)
		if digit_r in [2, 3, 4]:
			beer_word = 'piwa'
		elif digit_r == 1:
			beer_word = 'piwo'
		elif digit_r == 0:
			beer_word = 'mineralna'
		else:
			beer_word = 'piw'
		if beers == 1:
			return '{} {} {}'.format('Jedno'.capitalize(), beer_word, please)
		return '{} {} {}'.format(dict_units[digit_r].capitalize(), beer_word, please)


def ordering_beers(beers):
	num_0_to_19_in_polish = ('zero', 'jeden', 'dwa', 'trzy', 'cztery', 'piec', 'szesc', 'siedem', 'osiem', 'dziewiec', 'dziesiec', 'jedenascie', 'dwanascie', 'trzynascie', 'czternascie', 'pietnascie', 'szesnascie', 'siedemnascie', 'osiemnascie', 'dziewietnascie')
	tens_10_to_90_in_polish = ('dziesiec', 'dwadziescia', 'trzydziesci', 'czterdziesci', 'piecdziesiat', 'szescdziesiat', 'siedemdziesiat', 'osiemdziesiat', 'dziewiecdziesiat')
	if beers == 0:
		number = 'Woda'
		beverage = 'mineralna'
	elif beers == 1:
		number = 'Jedno'
		beverage = 'piwo'
	elif beers <= 19 and beers > 0:
		number = num_0_to_19_in_polish[beers]
		if beers in (2, 3, 4):
			beverage = 'piwa'
		else:
			beverage = 'piw'
	elif beers <= 99 and beers > 0:
		tens = beers // 10
		remains = beers % 10
		if remains == 0:
			number = tens_10_to_90_in_polish[tens - 1]
		else:
			number = tens_10_to_90_in_polish[tens - 1] + ' ' + num_0_to_19_in_polish[remains]
		if remains in (2, 3, 4):
			beverage = 'piwa'
		else:
			beverage = 'piw'
	else:
		raise Exception('输入变量越界')
	number1 = number.capitalize()
	return number1 + ' ' + beverage + ' poprosze'