I was writing one program in Spyder (Python 2.7). In this I wanted to check if the length of a list is equal to a number but it is showing errors.
N= int(raw_input())
10
num= raw_input()
20 20 21 21 22 22 23 23 24 24
num= num.split( )
num
Out[4]: ['20', '20', '21', '21', '22', '22', '23', '23', '24', '24']
if len(num)==N:
File "<ipython-input-5-513c0ce18f39>", line 1
if len(num)==N:
^
SyntaxError: unexpected EOF while parsing
len(num)
Out[6]: 10
if N== len(num):
print "Carry on!"
else:
print "Stop"
File "<ipython-input-7-6c369b6b221d>", line 2
print "Carry on!"
^
IndentationError: expected an indented block
len(N)
Traceback (most recent call last):
File "<ipython-input-8-e9708586568e>", line 1, in <module>
len(N)
TypeError: object of type 'int' has no len()
N
Out[9]: 10
if int(N)== len(num):
print "Carry on!"
else:
print "Stop"
File "<ipython-input-10-50bc38d8c831>", line 2
print "Carry on!"
^
IndentationError: expected an indented block
How to proceed in this case so that I can compare the length with given input N. And why the result appearing to be wrong? Help will be highly appreciated.
Aucun commentaire:
Enregistrer un commentaire