Comments (3)
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.
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.
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)
- Generate "final" variables if possible
- Show stdin as a separate channel when used in combination with arguments HOT 2
- Closing newline insertion HOT 1
- Specify interface that must be implemented
- Link bash compilation error to corresponding line in code
- Support before/after in DSL
- Support attribute assignment
- Update node.js to latest version HOT 3
- JavaScript: consider alternative ways to create object as alternatives HOT 1
- Bug with Javascript objects
- representation of Set and Map as return value HOT 3
- Add some extra tests for the set/map type restrictions
- Bump JavaScript exercises repo commit in tests
- Dodona features for language-agnostic exercices
- Measure/estimate complexity (time and memory) HOT 2
- Testing usage of specific keywords?
- Add C++ support
- Report non-zero exit status (use 0 as default exit status) HOT 5
- Extra dependencies
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from universal-judge.