Reputation: 1617
x1, y1, a1, b1, x2, y2 = int(input()), int(input()), int(input()), int(input()), int(input()), int(input())
My problem is to read 6 numbers each given on a new line. How to do that more laconically than my code above?
Upvotes: 4
Views: 288
Reputation: 17606
I would use dictionaries:
parm = {}
var_names = ['x1', 'y1', 'a1', 'b1', 'x2', 'y2']
for var_name in var_names:
parm[var_name] = int(input())
then you can transform dictionary keys into variables, but I do not think it is a good idea:
locals().update(parm)
Upvotes: 0
Reputation: 363487
x1, y1, a1, b1, x2, y2 = (int(input()) for _ in range(6))
Replace range
with xrange
and input
with raw_input
in Python 2.
Upvotes: 8
Reputation: 250871
x,y,z,w=map(int,input().split()) #add input in form 1 2 3 4
>>> x,y,z,w=map(int,input().split())
1 2 3 4
>>> x
1
>>> y
2
>>> w
4
>>> z
3
Upvotes: 1