Code Coach - Safety Deposit Boxes, why my code don't work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Code Coach - Safety Deposit Boxes, why my code don't work?

You are robbing a bank, but you’re not taking everything. You are looking for a specific item in the safety deposit boxes and you are going to drill into each one in order to find your item. Once you find your item you can make your escape, but how long will it take you to get to that item? Task Determine the amount of time it will take you to find the item you are looking for if it takes you 5 minutes to drill into each box. Input Format A string that represent the items in each box that will be drilled in order (items are separated by a comma), and secondly, a string of which item you are looking for. Output Format An integer of the amount of time it will take for you to find your item. Sample Input 'gold,diamonds,documents,Declaration of Independence,keys' 'Declaration of Independence' Sample Output 20 This is my code, it works only in 4 cases: boxes = input().split(',') item = input() print((boxes.index(item)+1)*5)

22nd Dec 2019, 3:29 PM
Antek Olszewski
Antek Olszewski - avatar
8 Answers
+ 3
Coder Kitten thanks, due to your hint i was able to make my code work
22nd Dec 2019, 3:49 PM
Antek Olszewski
Antek Olszewski - avatar
+ 2
Coder Kitten the results are hidden I think, except for the first two test cases
22nd Dec 2019, 3:42 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
items = (input()) finding_item = (input()) time = 0 list_items = list(items.split(",")) time = (list_items.index(finding_item ) + 1 ) * 5 print(time) What are You thinking about my code?
5th Jun 2021, 9:12 PM
Przemysław Komański
Przemysław Komański - avatar
+ 1
Where is your attempt ?
22nd Dec 2019, 3:35 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
It is below Code Coach question content
22nd Dec 2019, 3:37 PM
Antek Olszewski
Antek Olszewski - avatar
+ 1
Antek Olszewski sorry, I just saw it.
22nd Dec 2019, 3:38 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
If you found your item you are looking for you must break the search. Else your code will take another 5 minutes for other item. items = str(input()) key = str(input()) items = items.split(',') time = 0 for i in items: if str(i) == key: time += 5 break else: time += 5 print (time)
11th Jun 2020, 7:59 PM
Jhon Doe
Jhon Doe - avatar
0
box = input().split(",") item = input() position = box.index(item) x = box[:pos] time = 0 for i in box: if box.index(i) <= pos: time += 5 print(time) try this! suggestions and corrections are welcomed
29th Dec 2022, 2:36 PM
Gambo Victory
Gambo Victory - avatar