Hello, it's a question count the number of n. | Sololearn: Learn to code for FREE!

-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

5/20/2022 10:44:54 AM

Akash Gupta

26 Answers

New Answer

+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.

+3

Akash Gupta Will you share me some more inputs & outputs

+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}')

+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).

+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..

+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)

+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..

+1

JayakrishnašŸ‡®šŸ‡³ it happens because of copy wait i will send the code again

+1

Prince Kumar Lothar JayakrishnašŸ‡®šŸ‡³https://code.sololearn.com/cDwm64jdKAx6/?ref=app input -23 54 12 5 Output:3 Input: 1 1 1 1 1 Output:0

+1

Akash Gupta Input 23 54 12 5 How the output is 3

+1

JayakrishnašŸ‡®šŸ‡³ compiler giving this error NZEC .

+1

Prince Kumar 3 number are greater than 10 that's why

+1

Akash Gupta A=list(map(int,input().split())) c=0 for i in A: if i>=(n:=10) : c+=1 print(c)

+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)))

+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)))

+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

+1

Akash Gupta Lothar JayakrishnašŸ‡®šŸ‡³ Codechef is not updated with the new features in Python Now take this one , I have already registered & solved it šŸ‘‡šŸ‘‡šŸ‘‡ A=list(map(int,input().split())) c=0 for i in A: if i>=10 : c+=1 print(c) https://code.sololearn.com/ckbHwo55eg8V/?ref=app https://www.sololearn.com/post/1682869/?ref=app

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..?

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?

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.