+ 4

Python data structures : Revenue Growth Project : only 1 testcase is passing

https://code.sololearn.com/c7aacbyzA07x/?ref=app

1st Feb 2023, 9:13 AM
Sanjay Kamath
Sanjay Kamath - avatar
11 odpowiedzi
+ 10
Sanjay Kamath , what your current code is doing: > it uses the dictionary values (ages) and build the sum of it. buf we need the sum of ticket prices. > what we need is: a variable thaf can hold the result that is generated in a conditional statement: > iterate through the dict for this case => age = 18 > if age is less than 18, add + 5 to variable > in all other cases, add + 20 to the variable (see the sample code in the file) > iterate through the dict for this case => age = N, coming from input > if age is less than N, add + 5 to variable > in all other cases, add + 20 to the variable (this code has to be done by you!) > an other issue is the output formula of your code that is not suitable for the required result. (see the sampld code in the file) >> in the sample code i have tried use meaningful variable names. https://code.sololearn.com/cUs7g5syOt4r/?ref=app
2nd Feb 2023, 4:18 PM
Lothar
Lothar - avatar
+ 8
Sanjay Kamath , Jayakrishna 🇮🇳 , the task description says: > .... (use int() to convert the result) using floor() or int() will give the same result, but int() does not need an import.
1st Feb 2023, 11:56 AM
Lothar
Lothar - avatar
+ 4
Sanjay Kamath It seems your answer is missing some more code to pass all test cases: Firstly, you need to calculate the initial total sales AND THEN calculate the sales with the user given age. So to do this you may need 2 separate variables for sales, sales1 and sales2 maybe. You can only accurately calculate the revenue growth if you have the previous sales figure AND the updated sales figure with the new age. You will also need proper counters to track the amount of adults and kids for EACH calculation
1st Feb 2023, 10:51 AM
Natan 🇹🇹
Natan 🇹🇹 - avatar
+ 3
Instead of floor, try to use ceil function.
1st Feb 2023, 11:09 AM
Jayakrishna 🇮🇳
+ 3
Lothar then what is the problem..? Can you add task description or link? One i know is find difference between at age 18 and input age. But seems this is different problem. Sanjay Kamath ?
1st Feb 2023, 12:32 PM
Jayakrishna 🇮🇳
+ 3
Jayakrishna 🇮🇳 Sir 🙏, I tried your solution, including suggestions by the other posters but the rounding off error still persists.
2nd Feb 2023, 3:10 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 3
Jayakrishna 🇮🇳 Sir, I am still stuck....With due diligence you are the person who is most likely to gain an insight into the problem. Please help if you can.
2nd Feb 2023, 4:20 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 3
Sanjay Kamath Ok. Now i got the task description and it states that "The ticket for an adult is $20, while the ticket for a child under 18 is $5." So you should find total ticket price as per ages first as cut-age is 18. next in same way, take cut-off age is the input age value. Next final result as per formula given and print integer casted value. Suppose ex: when age limit is 18 then ticket price for below 18 is 5$ , and others 20 , say grant total is 100 if input is 14 then, price for ticket below age 14 is 5$ and for others 20$ so grant total may be 200 print( int( 200-100) /100 * 100)) #1 Your code logic i dont understand it. I think it is wrong. The 'value' you are taking is the number of attendence, not the price.. If it is something else task you are trying then let me know. Add the description.. Hope it helps..
2nd Feb 2023, 9:10 AM
Jayakrishna 🇮🇳
+ 3
Sanjay Kamath you are taking new_age as input but changing its value in loop. Must take another variable for total also check 2nd loop if condition. revert it.
3rd Feb 2023, 11:24 AM
Jayakrishna 🇮🇳
+ 2
COWABUNGA - SOLVED 💌 All
3rd Feb 2023, 12:12 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
See the updated build.. still values do not tally.
3rd Feb 2023, 11:16 AM
Sanjay Kamath
Sanjay Kamath - avatar