Jump to content

How to input two integers in Python

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
lionaneesh

lionaneesh

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
I am trying to solve the problem Present at Enormous Input Test | CodeChef

I have made a small Python script to do my job :-
array = []

no_lines = 0

no = 0 

j=0 

div_no=0

no_lines = input()

no = input()

temp = no_lines 

while(no_lines>0) :

	i=0 

	i = input()

	array[j] = i

	j = j+1

	no_lines = no_lines - 1

j=0


while(j<temp) :

	if array[j] % no == 0 :

		div_no=div_no+1 

	j = j+1


print(div_no,"\n")

I am having a problem in Inputing 2 integers on the same line
no_lines = input()

no = input()

I am really confused...How to get a successful output:-

In case of the following input:-

7 3

1

51

966369

7

9

999996

11


Error:-

SyntaxError: unexpected EOF while parsing


Facing problems in understanding Raw sockets and Selectors in C :confused:....If anybody can help please mail me...:crying:

#2
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
Why is this in the C and C++ forum?

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Moved to the correct forum.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
manux

manux

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 234 posts
If you're using Python 2.x, input will evaluate the given expression, so if you enter "2 3", it will try to parse the expression.
You should have included the whole Traceback(the error message) because there I'm unsure of what your error is.

What you should do if you want to get multiple numbers in one line, in Python 2.x:
nstr = raw_input("Enter 2 numbers separated by a space: ") # say we enter "2 3"
narray = nstr.split(" ") # creates a list -> ["2","3"]
#the long way
nlist = []
for i in narray:
    nlist.append(int(i))
#the short way (using list comprehensions)
nlist = [int(i) for i in narray]
a,b = nlist
print a,b # will output "2 3"
#the one liner way:
a,b = [int(i) for i in raw_input("Enter 2 numbers").split(" ")]