How to read numbers in python conveniently?

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 of which is listed on a new line. How to do this more succinctly than my code above?

+4
source share
3 answers
 x1, y1, a1, b1, x2, y2 = (int(input()) for _ in range(6)) 

Replace range with xrange and input with raw_input in Python 2.

+8
source
 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 
+1
source

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 convert the dictionary keys to variables, but I don't think this is a good idea:

 locals().update(parm) 
0
source

Source: https://habr.com/ru/post/1438688/


All Articles