I do not know what to include in the code

Hello Rahul,
So I have been making a code of the above question. I am getting confused as to how do I need to enter the code since I cannot see the sample input. I do not know whether to add input from user or use the sample input already given.

But all of them are wrong. Like if you have time could you explain to me how the test sample works on the code that I have written.

thank you

Can you please share the code you have written.

so here is the code for the problem Simple Input : https://ide.codingblocks.com/s/655532

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

z = 0
list1 = []
n = int(input("How many numbers ? : "))
for x in range(n) :
y = int(input("Enter number : "))
list1.append(y)
for x in list1:
z = x + z
if z < 0:
break
print(x)

Yes This is my code and when I compile it, It successfully does it but when I submit code and Codestudio runs it, all the test cases are coming wrong.
Like I don’t understand what could be the pre-defined test cases that my code can comprehend and if I want to watch, I will lose every mark.
What should I do?

Hi @sarthakagg105

In the given problem statement, while taking an input form the user, user won’t pass the number of digits he/she would like to input as input , so as you are taking number of times would like to inputs thats why your code isn’t able any test case
Please Refer following code :
image

Hope this might helps :slight_smile:

Hi Rahul,
Thank You for solving the problem. I just had to look the problem in other view that is instead of for loop use while loop.
If we have been given a problem where the number is not specified that how many times the loop will run , use while loop and in it write the given the condition.

Thanks again!

Hi @sarthakagg105
here’s an approach using for loop :

image

In repeat() we give the data and give the number, how many times the data will be repeated. If we will not specify the number, it will repeat infinite times. In repeat(), the memory space is not created for every variable. Rather it creates only one variable and repeats the same variable.

Syntax: repeat(val, num)

Parameters:
val: The value to be printed.
num: If the optional keyword num is mentioned, then it repeatedly prints the passed value num number of times, otherwise prints the passed value infinite number of times.

Hope this might helps :slight_smile: