-5

I have just begun learning Python and I got stuck (1day experience :)). Couldn't you help me with my homework?

Exercise: We have module checkers with function is_triangle

The method signature with a documentation string:

def is_triangle(a, b, c):

   """

   :param a: length of first side

   :param b: length of second side

   :param c: length of third side

   :return: "True" if possible to create triangle with these sides. Otherwise "False"

   """

You should develop full set of tests that will verify this function. The solution should use the nosetest library and it should be carried out in one file like:

$ Python% your_file_name% .py

What should I write in this .py file?

Serenity
  • 35,289
  • 20
  • 120
  • 115
Alex
  • 1
  • 1
  • 1
    What do you think it means to be a triangle? You should have at least attempted this before asking. – ProfOak Apr 05 '15 at 19:52
  • come up with values for `a`, `b`, and `c` that should cause `is_triangle` to return `True`. then come up with values for `a`, `b`, and `c` that should cause `is_triangle` to return `False`. write a test function that tests that these values produce the appropriate results. then add code to your function `is_triangle` such that it actually produces the desired results. – abcd Apr 05 '15 at 20:10

1 Answers1

-1

In this .py file you should write

import nose.tools as nt

from checkers import is_triangle


def test_is_triangle():
    # Define test_a, test_b, and test_c here such that they should produce a
    # return value of False.
    nt.assert_false(is_triangle(test_a, test_b, test_c))

    # Redefine test_a, test_b, and test_c here such that they should produce a
    # return value of True.
    nt.assert_true(is_triangle(test_a, test_b, test_c))

You should then run this script in one of two ways:

$ nosetests your_file_name.py

or

$ python your_file_name.py  # as your instructor has requested.

The test should fail until you have a properly written is_triangle function. If you find that your initial tests are inadequate -- such that the tests pass even though is_triangle is incorrect -- add more.

abcd
  • 10,215
  • 15
  • 51
  • 85
  • Traceback (most recent call last): File "C:\Users\Aleksandr\Desktop\checkers_test.py", line 3, in from checkers import is_triangle File "C:\Users\Aleksandr\Desktop\checkers.py", line 15 $ nosetests your_file_name.py ^ SyntaxError: invalid syntaxC:\Python27 – Alex Apr 05 '15 at 20:37
  • have you added any code to `is_triangle`? you can't have a function with no code. at the least you need to add `pass`. – abcd Apr 05 '15 at 20:39
  • I have two .py files: checkers.py and checkers_test.py – Alex Apr 05 '15 at 20:46
  • checkers.py has: def is_triangle(a, b, c): pass """ :param a: length of first side :param b: length of second side :param c: length of third side :return: "True" if possible to create triangle with these sides. Otherwise "False" """ – Alex Apr 05 '15 at 20:47
  • What should I write in checkers_test.py? Couldn't you write it to give me an example. I can't understand the sequencing at all :( I need an example with instruction how to run it. Pleasee – Alex Apr 05 '15 at 20:53
  • `pass` should come after the docstring. what do you mean you "can't understand the sequencing at all"? i'm happy to answer specific questions, but right now it sounds to me like you're asking for someone to do your homework for you. if i were to give you all the code, you wouldn't learn very much, would you? – abcd Apr 05 '15 at 21:01
  • and what you should write in `checkers_test` is what i wrote in my answer. – abcd Apr 05 '15 at 21:10