x1, y1, a1, b1, x2, y2 = int(input()), int(input()), int(input()), int(input()), int(input()), int(input())
私の問題は、新しい行にそれぞれ与えられた6つの数字を読み取ることです。上記の私のコードよりも簡潔にそれを行う方法は?
x1, y1, a1, b1, x2, y2 = int(input()), int(input()), int(input()), int(input()), int(input()), int(input())
私の問題は、新しい行にそれぞれ与えられた6つの数字を読み取ることです。上記の私のコードよりも簡潔にそれを行う方法は?
x1, y1, a1, b1, x2, y2 = (int(input()) for _ in range(6))
Python2でとにrange
置き換えます。xrange
input
raw_input
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
私は辞書を使います:
parm = {}
var_names = ['x1', 'y1', 'a1', 'b1', 'x2', 'y2']
for var_name in var_names:
parm[var_name] = int(input())
そうすれば、辞書のキーを変数に変換できますが、それは良い考えではないと思います。
locals().update(parm)