Advertisement
go6odn28

course_planning

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