python The final challenge involves a series of integers inscribed on the outsid
ID: 3780012 • Letter: P
Question
python
The final challenge involves a series of integers inscribed on the outside of a treasure chest:
challenge4 = [323, 331, 323, 336, 319, 330, 322]
Also inscribed on the treasure chest is the String "treasurelieswithinthischest"
To solve this problem you must do the following:
The list of integers contains an encrypted password that will open the treasure chest.
The key to decrypting this password can be found in the String "treasurelieswithinthischest"
Use each letter of the String "treasurelieswithinthischest" and extract its value, where a=0, b=1, c=2, etc. Construct an integer that represents the sum of all letters in the String.
Next, subtract this number from each value in the list of numbers above. Convert the resulting values to characters where a=0, b=1, c=2, etc.
The final password:Explanation / Answer
Python Code:
challenge4 = [323, 331, 323, 336, 319, 330, 322]
s="treasurelieswithinthischest"
alphabet={'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,'i':8,'j':9,'k':10,'l':11,
'm':12,'n':13,'o':14,'p':15,'q':16,'r':17,'s':18,'t':19,'u':20,
'v':21,'w':22,'x':23,'y':24,'z':25}
count=0
for i in s:
if i in alphabet:
count+=alphabet[i]
print(count)
challenge=[]
for i in range(len(challenge4)):
challenge.append(challenge4[i]-count)
print(challenge)
for i in challenge:
for key, value in alphabet.items() :
if i==value:
print(key, end='')
The Final Password:
emerald
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.