- 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
26 Respuestas
+ 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.
+ 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
Jayakrishna🇮🇳 compiler giving this error NZEC .
+ 1
Prince Kumar 3 number are greater than 10 that's why
+ 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
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.
0
Jayakrishna🇮🇳 tell me another way to count the n in given list.
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
0
Go through this link you will understand the question.