Advertisement
Nenogzar

11.SoftUni_Course_Planning_Advanced_Lists

Feb 11th, 2024
1,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.53 KB | None | 0 0
  1. ADD_COMMAND = "Add"
  2. INSERT_COMMAND = "Insert"
  3. REMOVE_COMMAND = "Remove"
  4. SWAP_COMMAND = "Swap"
  5. EXERCISE_COMMAND = "Exercise"
  6. END_COMMAND = "course start"
  7.  
  8. initial_schedule_of_lessons_and_exercises = input().split(", ")
  9.  
  10. while True:
  11.     command_input = input().split(":")
  12.     command = command_input[0]
  13.     args = list(map(str, command_input[1:]))
  14.  
  15.     if command == END_COMMAND:
  16.         for i in range(1, len(initial_schedule_of_lessons_and_exercises) + 1):
  17.             print(f"{i}.{initial_schedule_of_lessons_and_exercises[i - 1]}")
  18.         break
  19.  
  20.     elif command == ADD_COMMAND:
  21.         if args[0] not in initial_schedule_of_lessons_and_exercises:
  22.             initial_schedule_of_lessons_and_exercises.append(args[0])
  23.  
  24.     elif command == INSERT_COMMAND:
  25.         lesson, index = args
  26.         if lesson not in initial_schedule_of_lessons_and_exercises:
  27.             initial_schedule_of_lessons_and_exercises.insert(int(index), lesson)
  28.  
  29.     elif command == REMOVE_COMMAND:
  30.         eventual_exercise = f"{args[0]}-Exercise"
  31.         if args[0] in initial_schedule_of_lessons_and_exercises:
  32.             initial_schedule_of_lessons_and_exercises.remove(args[0])
  33.         if eventual_exercise in initial_schedule_of_lessons_and_exercises:
  34.             initial_schedule_of_lessons_and_exercises.remove(eventual_exercise)
  35.  
  36.     elif command == SWAP_COMMAND:
  37.         first_title, second_title = args
  38.         if first_title in initial_schedule_of_lessons_and_exercises and second_title in initial_schedule_of_lessons_and_exercises:
  39.             exercise_1_for_swap, one = "", False
  40.             exercise_2_for_swap, two = "", False
  41.             exercise_one, exercise_two = f"{first_title}-Exercise", f"{second_title}-Exercise"
  42.             if exercise_one in initial_schedule_of_lessons_and_exercises:
  43.                 initial_schedule_of_lessons_and_exercises.remove(exercise_one)
  44.                 exercise_1_for_swap = exercise_one
  45.                 one = True
  46.             if exercise_two in initial_schedule_of_lessons_and_exercises:
  47.                 initial_schedule_of_lessons_and_exercises.remove(exercise_two)
  48.                 exercise_2_for_swap = exercise_two
  49.                 two = True
  50.             position_first_title = initial_schedule_of_lessons_and_exercises.index(first_title)
  51.             position_second_title = initial_schedule_of_lessons_and_exercises.index(second_title)
  52.             initial_schedule_of_lessons_and_exercises[position_first_title], initial_schedule_of_lessons_and_exercises[position_second_title] = initial_schedule_of_lessons_and_exercises[position_second_title], initial_schedule_of_lessons_and_exercises[position_first_title]
  53.             if one:
  54.                 initial_schedule_of_lessons_and_exercises.insert(position_second_title + 1, exercise_1_for_swap)
  55.             if two:
  56.                 initial_schedule_of_lessons_and_exercises.insert(position_first_title + 1, exercise_2_for_swap)
  57.  
  58.     elif command == EXERCISE_COMMAND:
  59.         lesson_title = args[0]
  60.         exercise = f"{lesson_title}-Exercise"
  61.         if lesson_title in initial_schedule_of_lessons_and_exercises and exercise not in initial_schedule_of_lessons_and_exercises:
  62.             position = initial_schedule_of_lessons_and_exercises.index(lesson_title)
  63.             initial_schedule_of_lessons_and_exercises.insert(int(position + 1), exercise)
  64.         elif lesson_title not in initial_schedule_of_lessons_and_exercises:
  65.             initial_schedule_of_lessons_and_exercises.append(lesson_title)
  66.             initial_schedule_of_lessons_and_exercises.append(exercise)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement