๐ฅ URGENT๐ฅ My code is not working properly on a question (๐ฅ NEW DRIVER'S LICENSE ๐ฅ) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
+ 1

๐ฅ URGENT๐ฅ My code is not working properly on a question (๐ฅ NEW DRIVER'S LICENSE ๐ฅ)

myname=str(input()) agents=int(input()) p1=str(input()) lst=[] p2=(p1+" "+myname) x=p2.split() for i in range(0,len(x)): lst.append(min(x)) x.remove(min(x)) i=i+1 if lst.index(myname)+1<=agents: print(20) elif (lst.index(myname)+1)%agents==0: print(int((lst.index(myname)+1)/agents*20)) else: print(int((lst.index(myname)+1)/agents*20+20))

23rd Feb 2021, 5:19 AM
Sid
+ 3
Thanks #Calvin Sheen Thomas๐ But I want to know my error..โก
23rd Feb 2021, 5:37 AM
Sid
+ 3
23rd Feb 2021, 7:01 AM
Rik Wittkopp
+ 3
Sid You should be able to copy/paste the previous post into playground to play with. The main problem you have in your code is that the names of the clients haven't been sorted alphabetically. Do that, and then you are starting to get close to resolving. There is one more issue, but I will post later. Wife serving tea now. ๐๐
23rd Feb 2021, 7:05 AM
Rik Wittkopp
+ 3
Sid Ok, I'm back! The last part of your code has a lot of if, elif, else stuff happening where you are trying to control scenarios. This could be done with 1 line of code using math to do the work for you Examples may be the best way to explain: Example 1 You are first in line, and agents =5 We know the answer will be 20, but how. 1/5 = 0.2 Round up =1 1* 20 = 20 Example 2 You are 4th in line. agents = 3 4/3 = 1.3 Round up = 2 2 * 20 = 40 Spot the pattern and get the math to do the work. There are a couple of ways to round up in Python I will let you do some research. Hope this helps, ask if you get stuck
23rd Feb 2021, 7:42 AM
Rik Wittkopp
+ 3
PS: Oops! Just discovered I made a mistake. The section I marked as not sorting your list DOES sort your list. I was testing with a name that wasn't capitalised and got a list that looked similar to the original.
23rd Feb 2021, 7:49 AM
Rik Wittkopp
+ 2
name = input() agents = int(input()) others = input().split() + [name] others.sort() x = others.index(name) print(20 * ((x + (agents - x % agents)) //agents)) This is my solution, hope it helps; sorry but I didn't want to modify your code.
23rd Feb 2021, 5:32 AM
Calvin Thomas