0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

問題概要

10以上99以下の整数が与えられる。
2桁の合計を出力せよ。

解法と実装

10の位はXを10で割った商、1の位はXを10で割ったあまりなので、それぞれを足して出力することで答えが得られます。

X = int(input())
print((X//10) + (X%10)) # 商とあまりを出力

文字列として受け取って、それぞれの桁を数値型にして答えることもできます。

X = input() # 入力を受け取る
a = int(X[0]) # 10の位をint型にする
b = int(X[1])
print(a+b) # 足して答えを出力
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?