+ 1

Safety deposit boxes

#yet another broken piece of code def steal(items, item): time=0 items=[].split(",") for index in items: if items[index]==item: return 5 else: time+=5 return time print(steal(int(input()), int(input())))

1st Oct 2023, 8:04 PM
Annihilate
Annihilate - avatar
10 Respostas
+ 6
Trey , there are several issues to solve: > input is requested to be 2 strings, but your input tries to create int values, which will raise an exception. (input / output samples from the task description are still missing) > split() is not correctly done. > the logic in the for loop is not completely correct.
1st Oct 2023, 9:09 PM
Lothar
Lothar - avatar
+ 2
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.
1st Oct 2023, 8:29 PM
Annihilate
Annihilate - avatar
+ 2
Also, please save your code in the playground and post a link here. Those of us who want to help don't need/want the extra work of parsing your code out of your post. but i'll give you props for already commenting out the non-code!
1st Oct 2023, 8:54 PM
Aaron Lee
Aaron Lee - avatar
+ 2
Instance of “list” has no “split” member
1st Oct 2023, 10:37 PM
Annihilate
Annihilate - avatar
+ 1
Lothar mentioned something incorrect about the .split(), your code is giving you an error because of that .split() So let's look at that line: items = [].split(",") what are you wanting to do with this line of code?
1st Oct 2023, 11:56 PM
Aaron Lee
Aaron Lee - avatar
+ 1
It is nice to see someone try to use functional programming principle, although it is not required in this challenge. Set the split() method aside as Aaron Lee & Lothar already mentioned, you have a miss understanding about list indexing. In the lines below for index in items: if items[index] == item: What is the value of index is holding? What value are you expecting? There are other issues too, but you can fix some of them from our hints, and try to look at the error message and debug the code yourself.
2nd Oct 2023, 5:24 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
what error are you getting?
1st Oct 2023, 9:05 PM
Aaron Lee
Aaron Lee - avatar
0
So what lines need to be changed?
2nd Oct 2023, 9:04 PM
Annihilate
Annihilate - avatar