#1 複数の値が1行に同時に入力された場合、数値として取り込む
入力値 --- 以下の3つの数値を入力したら、int型として取り込む
100 3 123456
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#1 複数の値が1行に同時に入力された場合、数値として取り込む | |
# 入力値 --- 以下のように3つの数値が入力されて、int型として取り込む | |
# 100 3 123456 | |
# input | |
a, b, c = map(int,input().split()) | |
# output | |
print('output---') | |
print('a=%d' % a) | |
print('b=%d' % b) | |
print('c=%d' % c) |
(py3) toshi$ python python3-input.py
100 3 123456
output---
a=100
b=3
c=123456
#2 入力行数を最初に入力して、その後、複数行に渡る入力値を、配列として取り込む
入力値 --- 以下のように入力したら、3*3の行列として取り込む
3
1 2 3
4 5 6
7 8 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#2 入力行数を最初に入力して、その後、複数行に渡る入力値を、配列として取り込む | |
# 入力値 --- 以下のように入力したら、3*3の行列として取り込む | |
# 3 | |
# 1 2 3 | |
# 4 5 6 | |
# 7 8 9 | |
# input | |
n = int(input()) | |
a = [] | |
for i in range(n): | |
a.append(list(map(int,input().split()))) | |
# output | |
print('output---') | |
print(a) |
(py3) toshi$ python python3-input2.py
3
1 2 3
4 5 6
7 8 9
output---
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
0 件のコメント:
コメントを投稿