0
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

docker(98) 8÷2(2+2)をpythonで

Last updated at Posted at 2018-10-24

適用するルールによって意見は二分 「8÷2(2+2)=」の答えは?
https://news.livedoor.com/article/detail/16867682/?fbclid=IwAR0X6-jUxNWLWaE6RouXezm5mAsOPxK-amkEsp1k5ocln0bSiixUy_WDVbc

適用する言語で、答えはいっぱい。python3では。

macOS
$ python3
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:04:09) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 8÷2(2+2)
  File "<stdin>", line 1
    8÷2(2+2)
     ^
SyntaxError: invalid character in identifier

>>>8 / 2 (2 + 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> 8 / 2 * (2 + 2)
16.0
>>> 8/(2*(2+2))
1.0
>>> ctrl+D

python2では

macOS
$ python2.6
 (unknown, Feb  7 2017, 00:08:08) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> 8÷2(2+2)
  File "<stdin>", line 1
    8÷2(2+2)
     ^
SyntaxError: invalid syntax

>>> 8 / 2 ( 2 + 2 )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> 8 / 2 * ( 2 + 2 )
16
>>> 8/(2*(2+2))
1

docker

/home/python3にファイルを置いています。

$ docker run  -v /tmp/docker:/tmp/docker -it kaizenjapan/python23 /bin/bash

-v /tmp/docker:/tmep/dockerは、dockerを起動するシステムに/tmp/dockerというフォルダが利用可能な場合に記載。フォルダ名は、利用できるもので、docker側が空のものであればよい。

docker(89) dockerでpython2, python3
https://qiita.com/kaizen_nagoya/items/ecbe11a4d743357134d5

# python2.7
Python 2.7.17 (default, Nov  7 2019, 10:07:09) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 8÷2(2+2)
  File "<stdin>", line 1
    8÷2(2+2)
     ^
SyntaxError: invalid syntax
>>> 8 / 2 ( 2 + 2 )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> 8 / 2 * ( 2 + 2 )
16
>>> 8/(2*(2+2))
1

# python3.8
Python 3.8.0 (default, Oct 28 2019, 16:14:01) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 8÷2(2+2)
  File "<stdin>", line 1
    8÷2(2+2)
      ^
SyntaxError: invalid character in identifier
>>> 8 / 2 (2 + 2)
<stdin>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> 8 / 2 * (2 + 2)
16.0
>>> 8/(2*(2+2))
1.0
>>> 

python2, python3で動くファイルにする。

eight.py
#! /usr/bin/env python3
# coding: utf-8
# docker(98) 8÷2(2+2)をpythonで
print (8 / 2 * (2 + 2))
print (8/(2*(2+2)))

docker上で動作させる。

docker/ubuntu
# python2.7 eight.py
16
1
# python3.8 eight.py
16.0
1.0

#参考資料(reference)
プログラムちょい替え(11) Fortran 多次元配列のアクセス順序による計算時間の違い
https://qiita.com/kaizen_nagoya/items/3d657649d74fdd753bad

#まとめ(summary)

Python 3.6.1/3.8.0 Python 2.6.9/2.7.17
8÷2(2+2) SyntaxError: invalid character in identifier SyntaxError: invalid syntax
8/2(2+2) TypeError: 'int' object is not callable TypeError: 'int' object is not callable
8/2*(2+2) 16.0 16
8/(2*(2+2)) 1.0 1

文書履歴(document history)

ver. 0.01 初稿 20190822
ver. 0.02 加筆 20181024
ver. 0.03 docker追記 20191231

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
8
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
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?