OneCompiler

Computer Science

#Congratulations, Agent! 🕶️ You have been selected for a top-secret Python coding mission. Your objective is to decode mysterious data using list slicing, string slicing, and loops. Follow the challenges below and report back with your findings.
#Part A: The Secret List of Treasures
#You have discovered an ancient list containing treasures hidden in different locations. However, only a part of the list is visible at a time!
#Your Task:
#Create a list called treasures with at least 6 different treasures (gold, diamonds, a magic wand, etc.).
#Slice and print:
#The first three treasures found.
#The last two treasures found.
#The middle three treasures found.
#Use slicing to reverse the list (print it backward).
#Part B: The Mysterious Spy Message
#A top-secret message has been intercepted, but it’s scrambled! You must extract the hidden code from it.
#C#reate a string variable spy_message = "XJ9H4 Top-secret mission ahead! 3P2Q8"
#Use slicing to extract only "Top-secret mission ahead!" and print it.
#Use slicing to extract "XJ9H4" and "3P2Q8" separately. These are agent codes.
#Slice and print the last five characters of spy_message (could be a clue!).

#Part A: The Secret List of Treasures

My Task

Treasures=[' El Dorado’s Gold',' Koh-i-Noor Diamond ','The Philosopher’s Stone', 'Excalibur (Magic Sword) ','The Cintamani Stone',' The Ark of the Covenant']
#printing
print(Treasures)
#slicing
print("The first three treasures found",Treasures[0:3])
print('The last two treasures found',Treasures[4:6])
print('The middle three treasures found',Treasures[1:4]) #here is not mid of these treasures because 6 is an even number so that I have choosen the first 3 middle numbers.
#reverse the list by slicing
print(Treasures[::-1])

#Part B: The Mysterious Spy Message
spy_message='XJ9H4 Top-secret mission ahead! 3P2Q8'
#Slicing
print(spy_message[6:31])
#agent codes
print(spy_message[0:5])
print(spy_message[32:])
#print agent codes in one line
ac_1 ='XJ9H4'
ac_2 ='3P2Q8'
print(ac_1 and ac_2)
#clue
print(spy_message[32:])
#Mission completed