from random import randint amount_init = randint(10, 200) amount_given = randint(0, amount_init) amount_left = amount_init - amount_given def agree(number, form1, form2, form3): last = number % 10 penult = number // 10 % 10 word = form3 if last == 1 and penulte != 1: word = form1 elif 2 <= last <= 4 and penult != 1: word = form2 return word word = agree(amount_init, "яблоко", "яблока", "яблок") sentence1 = "У Геннадия было %s %s." % (amount_init, word) word = agree(amount_given, "яблоком", "яблоками", "яблоками") sentence2 = "Он поделился %s %s с Чебурашкой." % (amount_given, word) word = agree(amount_left, "яблоко", "яблока", "яблок") sentence3 = "Теперь у Гены осталось всего %s %s." % (amount_left, word) print(sentence1) print(sentence2) print(sentence3)