Python Forum
Google Foobar- Code works in my IDE but not in foobar. Static method?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Google Foobar- Code works in my IDE but not in foobar. Static method?
#1
Question 
Hello!

I am doing one of the Google foobar challenges and my code returns the right values in my IDE, but not in foobar. I'm new to python and think I'm missing something on how foobar reads the code or calls the function. Help is much appreciated!

Here's my code:

def solution(area):
    totalarea=int(area)
    sq1calc=abs(totalarea ** 0.5)
    sq1 = int(sq1calc)
    sq1area = sq1 ** 2
    sq2calc=abs((totalarea - sq1area) ** 0.5)
    sq2 = int(sq2calc)
    sq2area = sq2 ** 2
    sq3calc=abs((totalarea - sq1area - sq2area) ** 0.5)
    sq3 = int(sq3calc)
    sq3area = sq3 ** 2
    sq4calc=abs((totalarea - sq1area - sq2area - sq3area) ** 0.5)
    sq4 = int(sq4calc)
    sq4area = sq4 ** 2
    print(sq1area,sq2area,sq3area,sq4area, sep=",")
solution()
Two test case input/outputs are provided and my code runs these fine in my IDE.

Test cases:
Input:
solution.solution(15324)
Output:
15129,169,25,1

Input:
solution.solution(12)
Output:
9,1,1,1

I've read that foobar used the 'static method' but I'm not quite sure what that means or how it applies. No error information is provided by foobar.

As a note, if I enter this into foobar, it says Test 2 passes:

def solution(area):
   print ("""9,1,1,1""")
Reply
#2
What is line 16 doing? As solution requires a single argument, that line should generate an error.

I would normally expect the function to return data rather than print it. But if that fake one works with just the print statement, I guess they just want the printout.

How do you know that your code is returning different values in foobar? Is it possible that the code is doing the same thing in both foobar and your local system, but that foobar is checking an edge case and thinks the answer is wrong?
Reply
#3
(Feb-20-2021, 04:05 AM)bowlofred Wrote: What is line 16 doing? As solution requires a single argument, that line should generate an error.

I would normally expect the function to return data rather than print it. But if that fake one works with just the print statement, I guess they just want the printout.

How do you know that your code is returning different values in foobar? Is it possible that the code is doing the same thing in both foobar and your local system, but that foobar is checking an edge case and thinks the answer is wrong?

Thank you for reading!

Foobar shows the result for each test, the two provided test cases and eight other hidden cases, like below:

Test 1 failed
Test 2 passed!
Test 3 failed [Hidden]
Test 4 failed [Hidden]
Test 5 failed [Hidden]
Test 6 failed [Hidden]
Test 7 failed [Hidden]
Test 8 failed [Hidden]
Test 9 failed [Hidden]
Test 10 failed [Hidden]

So using my code, I know at least Test 1 and 2 should pass.

Line 16 "Solution()" was for testing in my IDE. I input 12 or 15324 in the () to check output. I excluded line 16 in foobar.

How do I use a return statement with , separators between the numbers?
Reply
#4
What is the required result of the test? Is it just supposed to print information to stdout? In any particular format? Can you get the first test to pass as well as the second?

If you wanted to return a string, then something like

return ",".join(sq1area,sq2area,sq3area,sq4area)
Or a tuple
return sq1area,sq2area,sq3area,sq4area
But if test2 is passing, the return value doesn't seem to be necessary.
Reply
#5
Quote:
def solution(area):

What if you don't pass a parameter? Or what if they pass None, a float, a string?

If you're sometimes passing the test case, then either:
a) that's an accident, and you probably should have failed them all, or
b) the input doesn't match what you think it should be.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem usage of static method akbarza 5 533 Feb-03-2024, 07:43 AM
Last Post: paul18fr
  Static type checking with PyPy pitosalas 1 450 Dec-14-2023, 09:29 PM
Last Post: deanhystad
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 991 Nov-15-2023, 06:56 PM
Last Post: jst
  Class member become static Quasar999 1 673 Sep-16-2023, 12:52 PM
Last Post: deanhystad
  Code works but doesn't give the right results colin_dent 2 710 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Code used to work 100%, now sometimes works! muzicman0 5 1,427 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  Method works as expected on host machine but not on server gradlon93 4 1,072 Jan-05-2023, 10:41 AM
Last Post: DeaD_EyE
  Pyspark - my code works but I want to make it better Kevin 1 1,779 Dec-01-2021, 05:04 AM
Last Post: Kevin
Question email code works in 2.7 but not in 3 micksulley 3 2,572 Nov-04-2021, 09:44 PM
Last Post: micksulley
Photo Output Static image on HDMI2 random816382 0 1,397 Oct-18-2021, 11:21 AM
Last Post: random816382

Forum Jump:

User Panel Messages

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