+ 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
Sid - avatar
6 odpowiedzi
+ 3
Thanks #Calvin Sheen Thomas😊 But I want to know my error..⚡
23rd Feb 2021, 5:37 AM
Sid
Sid - avatar
+ 3
Hi Sid """ There are a number of problems with your code. I have made some minor changes and added comments to get you started. I will follow this post with more info Sample Input 'Eric' 2 'Adam Caroline Rebecca Frank' Sample Output 40 """ myname=input() agents=int(input()) p1=input() #lst=[] # redundant p2=(p1+" "+myname) lst=p2.split() # this creates your list print(lst) # show your list ''' This section is another way to create your list for i in range(0,len(x)): lst.append(min(x)) x.remove(min(x)) i=i+1 print(lst) # show repeat list ''' 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, 7:01 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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
Rik Wittkopp - avatar
+ 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
Rik Wittkopp - avatar
+ 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
Rik Wittkopp - avatar
+ 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
Calvin Thomas - avatar