Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read numbers in python conveniently?

Tags:

python

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?

like image 445
nhtrnm Avatar asked Jan 15 '23 08:01

nhtrnm


2 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.

like image 54
Fred Foo Avatar answered Jan 17 '23 23:01

Fred Foo


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
like image 34
Ashwini Chaudhary Avatar answered Jan 17 '23 21:01

Ashwini Chaudhary