!usr/local/bin/python

i=0
n=long(raw_input())
while i b=long(raw_input())
c=long(raw_input())
a=b*c
print a
i=i+1

whats the problem in this coding?how to deal with huge numbers?I am new to this language so plz help me out with this problem?And also how to get the i/p in this format as 10 20 means 'a' should take the value 10 and 'b' should take the value as 20..

  • created

    Jan '07
  • last reply

    Feb '07
  • 1

    reply

  • 116

    views

  • 2

    users

for i in range(input()):
    b,c=[long(x) for x in raw_input().split()]
    print b*c

That's at least how I would do it.
The long b,c= line can be replaced by the more understandable
rawb,rawc=raw_input().split()
b=long(rawb)
c=long(rawc)

First line "for i in range(input()):" iterates over [0,n) where n is the first line of input as an integer: input() parses input (so it will give integer for input like {12}, string for {"Hello"}, tuple for {(1,2,3)}, so on...). range() should be familiar to you.
Second line "b,c=[long(x) for x in raw_input().split()]" is a list comprehension. It is a relatively new feature that is quite powerful, allowing complex statements to be expressed with a simple syntax. Basically, it means that for each item in raw_input().split(), it will get the value as a long and add that to an array.
.split() will split an input line across a whitespace boundary.
You can also use "map(long,raw_input().split())" for a shorter line, but note that map, filter and reduce are in the process of being deprecated (I really wish that they would keep reduce though frowning )
Third line should be pretty obvious: print the product b*c.