- 1

Hello, it's a question count the number of n.

A=list(map(int,input().split())) n=10 for i in A: if i>=n: count+=1 print(count) As you can see I'm able to count the number n in the list but whenever i give input which is less than it want to print (0) but I'm unable to do that can anyone tell me how can i do that. Input: 1 1 1 1 Output : No

20th May 2022, 10:44 AM
Akash Gupta
Akash Gupta - avatar
22 Answers
+ 4
Akash Gupta , additionally to the comment from Jayakrishna🇮🇳 : - the variable 'count' has to be declared and initialized before it is used - the final print() statement has to be without any indentation in general, the task description is missing a bit what you really wanted to count. - do i understand it correctly that you are expecting n input values as numbers separated by a space? - and you are then counting only numbers that are greater or equal than 10? may be you can update your task description.
20th May 2022, 11:00 AM
Lothar
Lothar - avatar
+ 2
Akash Gupta , here is your code slightly modified. t=int(input()) count=0 for i in range(t): n=10 inp = int(input()) if inp>=n: count+=1 print(f'number of values greater than {n}: {count}')
20th May 2022, 8:17 PM
Lothar
Lothar - avatar
+ 2
Lothar His original code, taking first input as how many lines of input and using split then for each line of input. Ex: input 2 23 12 7 22 1 1 1 1 So i added t input and loop. imput data are space separated, t times (see in linked code).
20th May 2022, 8:36 PM
Jayakrishna 🇮🇳
+ 2
Akash Gupta Your input / output explanations are 2 versions. Which one you actually trying? What is the task? You can add link here or copy paste here.. I modified code for the code you added by link as you said it update code.. Is you need modification for original you added in question description? @Lother given the modified version for that. If anything not work then add clear details by copy-pasting question and expected input/output details.. Hope you understand..
21st May 2022, 9:04 AM
Jayakrishna 🇮🇳
+ 2
It asking sign in... Can you share output screen shot..! Try this: A=input().split() count = 0 for i in A: i =int(i) if 1<= i <= 100 and i >= 10: count+=1 print(count)
21st May 2022, 4:09 PM
Jayakrishna 🇮🇳
+ 1
Identation matters in python. Pls save code and share link here.. edit: Akash Gupta 1>=10 false so no output. in all cases since print is inside if block..
20th May 2022, 10:46 AM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 it happens because of copy wait i will send the code again
20th May 2022, 3:58 PM
Akash Gupta
Akash Gupta - avatar
+ 1
20th May 2022, 4:02 PM
Akash Gupta
Akash Gupta - avatar
+ 1
Jayakrishna🇮🇳 compiler giving this error NZEC .
20th May 2022, 5:37 PM
Akash Gupta
Akash Gupta - avatar
+ 1
Prince Kumar 3 number are greater than 10 that's why
20th May 2022, 5:38 PM
Akash Gupta
Akash Gupta - avatar
+ 1
NREC => ? Is this full error description? You can use filter : t=int(input()) for i in range(t): A = filter(lambda x:x>10, map(int, input().split() )) print(len(list(A)))
20th May 2022, 7:29 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 , for your attempt we don't need to use a range for the input, since the input in the filter will be split and then mapped and processed by the lambda: #t=int(input()) #for i in range(t): A = filter(lambda x:x>10, map(int, input().split() )) print(len(list(A)))
20th May 2022, 8:15 PM
Lothar
Lothar - avatar
+ 1
A=list(map(int,input().split())) count = 0 for i in A: if i>=10: count+=1 print(count) #or A=filter(lambda x : x>=10 and x<=100 , map(int,input().split())) print(len(list(A))) #try these two variations
21st May 2022, 2:16 PM
Jayakrishna 🇮🇳
0
Akash Gupta Input: 2 -23 54 12 5 1 1 1 1 1 Getting Output: 2 0 What is your expected output? "able to count number of n in list" - What do you mean by this ? Explanation not matching with code!! Can you clarify it..?
20th May 2022, 4:23 PM
Jayakrishna 🇮🇳
0
Akash Gupta No. Am not getting any error. I posted above test cases and output. I taken -23 so. If it is +23 then output is 3 What is your expected output?
20th May 2022, 5:43 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 bro you can tell me any different approach for that this code is executed correctly on online compiler but when i submitted on coding contest compiler it giving me error of NREC it's a logical error in my code.
20th May 2022, 6:36 PM
Akash Gupta
Akash Gupta - avatar
0
Jayakrishna🇮🇳 tell me another way to count the n in given list.
20th May 2022, 6:37 PM
Akash Gupta
Akash Gupta - avatar
0
Jayakrishna🇮🇳 Same error by implementing your code. Run time error NZEC Error Traceback (most recent call last): File "./prog.py", line 2, in <module> ValueError: invalid literal for int() with base 10: '12 15 8 10' If you want to read problem.. practice makes us perfect codeshef problem. Please search on google
21st May 2022, 8:38 AM
Akash Gupta
Akash Gupta - avatar
0
Go through this link you will understand the question.
21st May 2022, 10:34 AM
Akash Gupta
Akash Gupta - avatar