Advertisement
Martin_D24

11 задача - SoftUni Course Planning

Oct 18th, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. def handle_course_start(current_schedule, current_exercises):
  2.     for i in range(len(current_schedule)):
  3.         for element in current_exercises:
  4.             if element == current_schedule[i]:
  5.                 current_schedule.insert(i+1, f'{element}-Exercise')
  6.  
  7.     for i in range(len(current_schedule)):
  8.         print(f"{i + 1}.{current_schedule[i]}")
  9.  
  10.  
  11. schedule = input().split(", ")
  12. exercises = []
  13.  
  14. while True:
  15.     command = input()
  16.     if command == "course start":
  17.         handle_course_start(schedule, exercises)
  18.         break
  19.     command = command.split(":")
  20.     action = command[0]
  21.     first_new_lesson = command[1]
  22.  
  23.     if action == "Add":
  24.         if first_new_lesson not in schedule:
  25.             schedule.append(first_new_lesson)
  26.  
  27.     elif action == "Insert":
  28.         if first_new_lesson not in schedule:
  29.             index = int(command[2])
  30.             if 0 <= index < len(schedule):
  31.                 schedule.insert(index, first_new_lesson)
  32.  
  33.     elif action == "Remove":
  34.         if first_new_lesson in schedule:
  35.             index_of_exercise = schedule.index(first_new_lesson)
  36.             schedule.remove(first_new_lesson)
  37.  
  38.     elif action == "Swap":
  39.         second_new_lesson = command[2]
  40.         if first_new_lesson in schedule and second_new_lesson in schedule:
  41.             first_index = schedule.index(first_new_lesson)
  42.             second_index = schedule.index(second_new_lesson)
  43.             schedule[first_index], schedule[second_index] = schedule[second_index], schedule[first_index]
  44.  
  45.     elif action == "Exercise":
  46.         if first_new_lesson in schedule:
  47.             exercises.append(first_new_lesson)
  48.         elif first_new_lesson not in schedule:
  49.             schedule.append(first_new_lesson)
  50.             exercises.append(first_new_lesson)
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement