Python3で1行でスペースで分けられた複数の数の和を求めるプログラムです。
# coding: utf-8
# 入力
input_line = input()
#数の和の変数を定義
goukei=0
#スペースで仕切って数字を取り出す
for num in input_line.split():
#データを整数型に変換して合計を求める
goukei += int(num)
#合計を標準出力する
print(goukei)
Go to list of users who liked
More than 1 year has passed since last update.
Python3で1行でスペースで分けられた複数の数の和を求めるプログラムです。
# coding: utf-8
# 入力
input_line = input()
#数の和の変数を定義
goukei=0
#スペースで仕切って数字を取り出す
for num in input_line.split():
#データを整数型に変換して合計を求める
goukei += int(num)
#合計を標準出力する
print(goukei)
Register as a new user and use Qiita more conveniently
Go to list of users who liked