問2.2(演算)
解答
type()でデータ型を表示させる。
ポイントになりそうなのは下記の通り。
- all([True, True, False]) : すべてTrueのときTrueを返す、AND回路
- any([True, True, False]) : どれか一つでもTrueのときTrueを返す、OR回路
- abs : 絶対値を返す
# 1.2 + 3.8 予想:float 5.0 x = 1.2 + 3.8 t = type(x) print(t,x) # => <class 'float'> 5.0
# 10 // 100 予想:int 0 x = 10 // 100 t = type(x) print(t,x) # => <class 'int'> 0
# 1 >= 0 予想:boolean True x = 1 >= 0 t = type(x) print(t,x) # => <class 'bool'> True
# 'Hello World' == 'Hello World' 予想:boolean True x = 'Hello World' == 'Hello World' t = type(x) print(t,x) # => <class 'bool'> True
# not 'Chainer' != 'Tutorial' 予想:boolean False x = not 'Chainer' != 'Tutorial' t = type(x) print(t,x) # => <class 'bool'> False
# all([True, True, False]) 予想:boolean False x = all([True, True, False]) t = type(x) print(t,x) # => <class 'bool'> False
# any([True, True, False]) 予想:boolean True x = any([True, True, False]) t = type(x) print(t,x) # => <class 'bool'> True
# abs(-3) 予想:int 3 x = abs(-3) t = type(x) print(t,x) # => <class 'int'> 3
# 2 // 0 予想:エラー? x = 2 // 0 t = type(x) print(t,x) # => ZeroDivisionError: integer division or modulo by zero
最後のやつは0で割ってるので、ZeroDivisionErrorが出力されている。