0
0

More than 1 year has passed since last update.

paizaラーニング「積の最小化 Python3編」

Last updated at Posted at 2022-11-21

https://paiza.jp/works/mondai/conditions_branch/conditions_branch__complex_boss
私の回答

a,b=[int(x) for x in input().split()]
if a<0 and b<0:
    print(b*b)
elif a<0 and b>0:
    print(a*b)
elif a==0 or b==0:
    print(0)
elif a>0 and b>0:
    print(a*a)

elifでプログラムを終了してしまい、中途半端になってしまいました。

模範回答

a, b = [int(x) for x in input().split()]

if a <= 0 and b >= 0:
    # a から b の間に 0 が含まれる
    print(a * b)
elif a > 0:
    # a と b が両方とも正の数
    print(a * a)
else:
    # a と b が両方とも負の数
    print(b * 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