Advertisement
go6odn28

softuni_course_planning

Feb 26th, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. initial_schedule = input().split(", ")
  2. command = input().split(':')
  3.  
  4. while command[0] != 'course start':
  5.     action = command[0]
  6.     lesson_title = command[1]
  7.     if action == 'Add':
  8.         if lesson_title not in initial_schedule:
  9.             initial_schedule.append(lesson_title)
  10.     elif action == 'Insert':
  11.         index = int(command[2])
  12.         if lesson_title not in initial_schedule:
  13.             initial_schedule.insert(index, lesson_title)
  14.     elif action == 'Remove':
  15.         if lesson_title in initial_schedule:
  16.             initial_schedule.remove(lesson_title)
  17.             lesson_exercise = f'{lesson_title}-Exercise'
  18.             if lesson_exercise in initial_schedule:
  19.                 initial_schedule.remove(lesson_exercise)
  20.     elif action == 'Swap':
  21.         lesson_title_second = command[2]
  22.         if lesson_title in initial_schedule and lesson_title_second in initial_schedule:
  23.             first_lesson_index = initial_schedule.index(lesson_title)
  24.             second_lesson_index = initial_schedule.index(lesson_title_second)
  25.             initial_schedule[first_lesson_index], initial_schedule[second_lesson_index] = \
  26.                 initial_schedule[second_lesson_index], initial_schedule[first_lesson_index]
  27.             first_lesson_exercise = f'{lesson_title}-Exercise'
  28.             second_lesson_exercise = f'{lesson_title_second}-Exercise'
  29.  
  30.             if first_lesson_exercise in initial_schedule:
  31.                 initial_schedule.remove(first_lesson_exercise)
  32.                 if second_lesson_index + 1 == len(initial_schedule):
  33.                     initial_schedule.append(first_lesson_exercise)
  34.                 else:
  35.                     initial_schedule.insert(second_lesson_index + 1, first_lesson_exercise)
  36.  
  37.             if second_lesson_exercise in initial_schedule:
  38.                 initial_schedule.remove(second_lesson_exercise)
  39.                 if first_lesson_index + 1 == len(initial_schedule):
  40.                     initial_schedule.append(second_lesson_exercise)
  41.                 else:
  42.                     initial_schedule.insert(first_lesson_index + 1, second_lesson_exercise)
  43.  
  44.     elif action == 'Exercise':
  45.         if lesson_title not in initial_schedule:
  46.             initial_schedule.append(lesson_title)
  47.             lesson_exercise = f'{lesson_title}-Exercise'
  48.             lesson_title_index = initial_schedule.index(lesson_title)
  49.             if lesson_title_index + 1 < len(initial_schedule):
  50.                 initial_schedule.insert(lesson_title_index + 1, lesson_exercise)
  51.             else:
  52.                 initial_schedule.append(lesson_exercise)
  53.         else:
  54.             lesson_title_index = initial_schedule.index(lesson_title)
  55.             lesson_exercise = f'{lesson_title}-Exercise'
  56.             if lesson_exercise not in initial_schedule:
  57.                 if lesson_title_index + 1 < len(initial_schedule):
  58.                     initial_schedule.insert(lesson_title_index + 1, lesson_exercise)
  59.                 else:
  60.                     initial_schedule.append(lesson_exercise)
  61.  
  62.     command = input().split(':')
  63.  
  64. for count, value in enumerate(initial_schedule, start=1):
  65.     print(f"{count}.{value}")
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement