![]() |
Soccer Teams and Trains - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Soccer Teams and Trains (/thread-27872.html) Pages:
1
2
|
Soccer Teams and Trains - Uwotm888 - Jun-25-2020 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) RE: Soccer Teams and Trains - DPaul - Jun-25-2020 I'm not sure what the problem is, because it seems to work properly. 25 teams = 7 big and 4 small carts. Paul RE: Soccer Teams and Trains - Uwotm888 - Jun-25-2020 (Jun-25-2020, 06:13 AM)DPaul Wrote: I'm not sure what the problem is, because it seems to work properly. 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 RE: Soccer Teams and Trains - pyzyx3qwerty - Jun-25-2020 Let's see - the user enters 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. 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?
RE: Soccer Teams and Trains - Uwotm888 - Jun-25-2020 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 RE: Soccer Teams and Trains - DPaul - Jun-25-2020 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 RE: Soccer Teams and Trains - Uwotm888 - Jun-25-2020 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 RE: Soccer Teams and Trains - DPaul - Jun-25-2020 What about 2 teams ? I think your program will put them in 3 small carts as well. Paul RE: Soccer Teams and Trains - pyzyx3qwerty - Jun-25-2020 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 RE: Soccer Teams and Trains - DPaul - Jun-27-2020 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. |