Giter Site home page Giter Site logo

Comments (3)

niknetniko avatar niknetniko commented on September 20, 2024 1

If you want to test it in the same tab, you could do something like this:

- tab: "test function and main"
  contexts:
    - testcases:
        - stdin: |
            100
            120
          stdout: "109.09"
        - expression: "harmonisch_gemiddelde(100, 120)"
          return: 109.99

Separate tabs are currently a limitation of TESTed: either you need to add if __name__ == '__main__': (but then the main code won't be executed) or you don't (in which case the code always runs).

This is something we want to enable at some point (as it has been requested before here), but the specifics of Python make this difficult, so we don't have a solution yet.

from universal-judge.

DieterPi avatar DieterPi commented on September 20, 2024

Thanks for the reply! Your suggestion would work. A separate tab would be a 'cleaner' solution for students, but this will also do the trick. 👍️

Could you elaborate on the if __name__ == '__main__': suggestion? How does that work? (I need to insert it as a user into my code?)

from universal-judge.

niknetniko avatar niknetniko commented on September 20, 2024

When creating a Python module that has both functions and is usable as a script, it is common to write it with a guard:

def harmonic_mean( a, b ):
    value = round( 2 / ( 1 / a + 1 / b ), 2)
    return value 

if __name__ == '__main__':
    # Input
    a = int(input())
    b = int(input())

    # Using the function
    c = harmonic_mean(a,b)

    # Printing on screen
    print(c)

This is basically the "main" function from other languages. In the future if/when we support separate tabs, you will probably need to write the submission like this. But, to be clear, this currently will not work in TESTed.

from universal-judge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.