I keep getting the message "no response on stdout"

Hi, I’m doing a problem on hackerrank and every time I submit my problem I get this message “no response on stdout” as my output. Below is my code. Here is a link to the problem:

Disclaimer: the reason I did not post the question on here was because the problem was not specific to a single question but a number of questions. There is something about the format of the problem that I do not understand, not the question itself. Thank you

def countingValleys(n, s):


    n = int(input())

    s = input()

    L = 0
    V = 0
    for el in s:
        if s == 'U':
            L+= 1
            if L == 0:
                V += 1
        else:
            L -= 1
    print(V)

You need to return V as well. Right now, your print(V) statement will show as the debug output, but make sure you always check out their included code:

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    s = input()

    result = countingValleys(n, s)

    fptr.write(str(result) + '\n')

    fptr.close()

Here, you want to make sure countingValleys returns a value, so that when it is assigned to result, the program can write it out in stdout.

1 Like

Thanks for helping. Did you have an example of some code that put out an answer besides “no response on stdout”. If possible could you post it?

Just delete these two lines from your function:

and add return V at the bottom of it. It should work fine.

I still can’t get it to work. Everything I’ve tried so far had ended in the same result, but thanks for your help anyways

Maybe you deleted something from their included code?

Here is what the whole code looks like when I pass it:

Click here for code
#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the countingValleys function below.
def countingValleys(n, s):
    elevation = 0
    valleys = 0

    for c in s:
        if c == 'U':
            elevation += 1
            if elevation == 0:
                valleys += 1
        elif c == 'D':
            elevation -= 1

    print(valleys)
    return valleys
    

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    s = input()

    result = countingValleys(n, s)

    fptr.write(str(result) + '\n')

    fptr.close()

So long as you kept all of their code intact and you have a return statement in your function, you shouldn’t be getting an error about no response on stdout.

1 Like

Thanks man, It looks like all I had to do was keep the original code there without removing it