Python Forum
Soccer Teams and Trains
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Soccer Teams and Trains
#1
Essentially, the script is to take soccer teams (15 players per team) and calculate the cheapest carts to rent

big cart carry's 48 people costs $200 per cart
small cart carries 10 and costs $95.

So 1 team will = 2 small carts costing $190
2 teams will = 1 big cart costs $200 (same for 3 teams)

so on and so forth. My current script doesn't particularly function when doing more than 1 team it just keeps adding small carts. I know the issue is probably within the loop but I am unsure where exactly its going awol.

socTeam = int(input("How many teams?"))
socTeamPlayer = socTeam * 15
bigCart = 0
smallCart = 0


while socTeamPlayer > 0:
    if socTeamPlayer / 48 > 1:
        socTeamPlayer -= 48
        bigCart += 1
    else:
        socTeamPlayer -= 10
        smallCart += 1

cost = (bigCart * 200) + (smallCart * 95)
print("Hire", bigCart, "big Carts and", smallCart, "small Carts.")
print("Cost =", cost)
Reply
#2
I'm not sure what the problem is, because it seems to work properly.
25 teams = 7 big and 4 small carts.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#3
(Jun-25-2020, 06:13 AM)DPaul Wrote: I'm not sure what the problem is, because it seems to work properly.
25 teams = 7 big and 4 small carts.
Paul

You're somewhat correct, sorry for not clarifying as i only just found this out but

When entering 3 teams which should be 1 big cart, it returns 5 small carts it seems that it only craps out at 3 teams, and i'm not sure why
Reply
#4
Let's see - the user enters 3
Output:
How many teams? 3
So then, socTeamPlayer will be 3*15 = 45. Next, we go in the while loop. We do 45/48, which is lesser than 1, and so smallCart += 1 till it becomes lesser than 0, which will go 5 times. Therefore, the output you get is 5 small teams.
Output:
Hire 0 big Carts and 5 small Carts. Cost = 475
However, I don't understand your logic to help you solve your code. Could you explain it a bit more to help me understand it?
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#5
Essentially 5 small carts has 50 spaces in it (5 carts * 10 seats per cart) so yes 5 carts will fit 3 teams or 45 people (15 people per team HOWEVER 5 small carts costs $475.

The program should actually display 1 big cart, as 1 big cart contains 48 spaces and costs $200. so it will fit 3 teams and cost less than 5 small carts.

the program appears to work on every other team input
10 teams = 3 big cart 1 small cart $695
4 teams = 1 big cart 2 small cart $390

however
3 teams SHOULD = 1 big cart $200
NOT 5 small cart $475
Reply
#6
Do you also think that 6 carts should be 1 big and 5 small, or 2 big, which is cheaper?
You are going to have that problem with every number of players , a little bit less than 48, ( or a multiple) , i think.

It sounds to me that you want to "optimize" for least cost. That would require entirely different logic.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#7
All i know is that according to the answer sheet (note sheet does not display a correct code to use, only inputs and outputs) 3 teams should equal 1 big bus. All other teams that the sheet lists as inputs will output a correct response in my program (correct being what is listed as an output in the sheet)

It is possible the sheet is wrong or 3 is an outlier im just not entirely sure which is why i came here for a review.

Everything seems to work until 3 is entered
Reply
#8
What about 2 teams ? I think your program will put them in 3 small carts as well.

Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#9
Looks like you are trying to find the cheapest price if I'm not wrong. You could define each price option under variables and compare them to find out which is the least
And as DPaul mentioned, the program doesn't work for 2 either
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#10
Come to think of it, each time your program says there are 3 or more small carts needed, that is not optimal.
Because 1 big is always cheaper than 3 small.
You could correct that , before publishing the result, but that is fiddling and will win no prize :-)
As i look at it, your angle of attack should be chuncks of 30 people. They will always need to go in a big cart.
Als long as your balance is 30 or 30+ -> big carts.
Paul
Edit: only 1 line needs to be changed to make this work.
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020