+ 1

What's wrong with my code?

I tried to solve the new driver's license code coach But there is a bug in my code.i can't find it.please help me name = input() agents = int(input()) people = input() peoples = people.split(' ') peoples.append(name) srt_people = sorted(peoples) row_no = 0 for i in srt_people : if i == name : row_no +=1 break else: row_no +=1 counter = 0 while row_no > 0: row_no-= agents counter +=1 min_1= counter*20 min_1 = int(min_1) print(min_1)

20th Feb 2025, 2:23 PM
Sherwin
2 Antworten
+ 5
row_no represents your position in line, not the number of groups to process. You should divide row_no by agents correctly to determine how many time slots you need. Replace the while loop's code block(line 16-18) with this: counter = (row_no + agents - 1) // agents
20th Feb 2025, 2:55 PM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
+ 4
Sherwin you didn't specify, but from your code it looks like you are using python. 👉 people = input() peoples = people.split(' ') Can be combined into 1 line. peoples = input().split() # ' ' is default separator 👉 srt_people = sorted(peoples) Built-in list sort is called sort() and does not return anything. It sorts the list it is called on. peoples.sort() 👉 You can remove your entire for loop. There already exists built-in list method for finding index of first occurrence of an item in the list. row_no = peoples.index(name) 👉 You can remove your entire while loop. You know it takes 20 minutes for n agents to process n people in the queue. So just use floor divide on your index by number of agents, and multiply by 20 to get your wait time. Add 20 for your own processing time to find out how long for you to finish and leave. min_1 = 20 * (1 + row_no // agents) # / is regular division operator, returns float # // is floor divide operator, returns quotient as int
20th Feb 2025, 7:36 PM
Shardis Wolfe