0

Can anyone find any bug or problem with my code? I can't.

name = input() agent_count = int(input()) people = input() drivers = people.split() drivers.append(name) drivers.sort() batch = 1 license_duration = 1 if len(drivers)%2 == 0: length = len(drivers) else: length = len(drivers) + 1 for person in drivers: if person == name: pos = drivers.index(person) for count in range(agent_count, length+1, agent_count): if pos < count: license_duration = batch * 20 else: batch = batch + 1 print(license_duration)

10th Jun 2022, 4:03 PM
Swati Mishra
6 Antworten
+ 4
// There's 2 errors: - If the inputs are empty, the program will be stopped. - The variable "license_duration" is not defined, define it with "None" as default value. Inputs by default in python: https://stackoverflow.com/questions/22402548/default-values-on-empty-user-input
10th Jun 2022, 4:17 PM
program
program - avatar
+ 2
Currently, you are defining the variable "license_duration" inside 'if' block but that 'if' block is not getting executed because of logic and hence giving error. I didn't find any other problem with the code. If you can tell me what you want to achieve then maybe I will be able help you :)
10th Jun 2022, 4:59 PM
Sandeep
Sandeep - avatar
+ 2
Swati Mishra Before printing the last line, you need to define license_duration like this: license_duration = batch * 20 Currently, above line is inside 'if' statement and is not getting executed. I don't know the exact reason but I think this is the case when we have more agents and less drivers. This causes the for loop to not execute at all. Btw nice logic :) you have done some extra checks in your code and I think that is good.
11th Jun 2022, 4:10 AM
Sandeep
Sandeep - avatar
+ 1
If you can't then what's wrong? Are you coming across an error?
10th Jun 2022, 4:13 PM
Justice
Justice - avatar
+ 1
Sandeep you were right. Thanks everyone. I corrected the mistakes and it's working now. I passed.
12th Jun 2022, 3:52 PM
Swati Mishra
0
Even after correcting the license_duration definition, I'm not able to pass test case 3 of 'new driver's license '. Code is giving results. Please try seeing again what's wrong with the code.
10th Jun 2022, 8:40 PM
Swati Mishra