Answer the question
In order to leave comments, you need to log in
Task in Python, please help me understand the formula, how is it implemented?
Good day to all. Dear coders.
I am currently taking elementary courses in Python and there was such a problem:
At the Institute of Bioinformatics, a robot moves around the office. Recently, students from a group of programmers wrote a program for him, according to which the robot, when it enters a room, counts the number of programmers in it and says it out loud: "n programmers."
In order for this to sound correct, for each n you need to use the correct word ending.
Write a program that reads an integer n (non-negative) from user input, outputs this number to the console along with the correct word "programmer", so that the robot can communicate normally with people, for example: 1 programmer, 2 programmers, 5 programmers .
There can be a lot of programmers in a room. Check that your program will correctly handle all cases up to at least 1000 people.
Additional comment on the condition:
Please note that the task is not as simple as it seems at first glance. If your solution fails some test, it means that you didn't consider some of the input cases (number of programmers 0 ≤ n ≤ 1000). Be sure to check your solutions on additional values, and not just on those given in the condition of the assignment.
tp = int(input('Введите число: '))
if tp < 0:
print('Ошибка, введите положительное число')
elif tp % 10 == 1 and tp % 100 != 11: # Формула 1
print(tp, 'программист')
elif tp % 10 >= 2 and tp % 10 <= 4 and (tp % 100 < 10 or tp % 100 > 20): # Формула 2
print(tp, 'программиста')
else:
print(tp, 'программистов')
Answer the question
In order to leave comments, you need to log in
Numbers ending in 2, 3, 4, for example, 2, 22, 32, fall into formula 2 ("programmer").
However, if the last two digits are numbers 12-14, then they must be excluded: 12, 112, 212. .. (this is formula 3). Therefore, the remainder of the division by 100 is taken.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question