Files
Python_Basic/Module16/10_rhyme_cnt/main.py
2025-09-15 22:41:05 +05:00

25 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# TODO здесь писать код
count_people = int(input('Кол-во человек: '))
peoples = list(range(1, count_people + 1))
count_number = int(input('Какое число в считалке? '))
print(f'Значит, выбывает каждый {count_number}-й человек\n')
# Скорее всего не оптимальное решение.
# Решал чисто "интуитивно", с помощью дебага и "экспериментов" с вычислениями
leave = 0
while len(peoples) > 1:
print('Текущий круг людей:', peoples)
print('Начало счёта с номера', peoples[leave])
leave = (leave + count_number) % len(peoples)
if leave == 0:
leave = len(peoples) - 1
else:
leave -= 1
print('Выбывает человек под номером', peoples[leave])
print()
peoples.remove(peoples[leave])
if leave >= len(peoples):
leave %= len(peoples)
print('Остался человек под номером', peoples[0])