0

I'm currently learning python in a Zybooks interactive eText and need someone to help me understand why this isn't working. Zybooks tests a few different iterations of your code and this one is working for three and failing on their fourth test. They don't actually tell you what they are testing until you run the code... Any help understanding where I'm going wrong is appreciated.

Write a function shampoo_instructions() with parameter num_cycles. If num_cycles is less than 1, print "Too few.". If more than 4, print "Too many.". Else, print "N : Lather and rinse." num_cycles times, where N is the cycle number, followed by "Done.". Sample output for the given program: 1 : Lather and rinse. 2 : Lather and rinse. Done.

Here is what I wrote that works for three of the five tests...

def shampoo_instructions(num_cycles):
    if num_cycles < 1:
        print('Too few.')
    if num_cycles > 4:
        print('Too many.')
    else:
        N = 0
        while N < num_cycles:
            print(N+1, ': Lather and rinse.')
            N = N + 1
        print('Done.')

shampoo_instructions(2) #this cannot be changed in the exercise
8
  • 2
    Test your code with num_cycles=0. What do you see? Commented Feb 11, 2021 at 2:42
  • I did try changing the 1 to a zero and had the same result, test four still failed because Done was added. Commented Feb 11, 2021 at 3:20
  • You misunderstood my statement. I suggested calling your function passing 0 as the argument and observe the output, i.e. shampoo_instructions(0). Commented Feb 11, 2021 at 3:32
  • Sorry, still learning... The final line is not available for edit, it is part of the code they give you that you cannot change. Commented Feb 11, 2021 at 3:36
  • You don't have to use their environment; you can use any Python interpreter, or something like repl.it/languages/python3 . Once you debugged your solution you can paste it back to their system. Commented Feb 11, 2021 at 3:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.