2012-03-12 14 views
3

Person 1にはPython 3.xで書かれたpython実行可能ファイル(mac)があります。 Person 1はこのファイルをPerson 2に送信します。Person 2もMacを持っていますが、Python 2.6.1しか持っていません。 Person 2がそのファイルを実行すると動作しますか?以前のバージョンで動作するPython実行可能ファイル

誰かがそう、彼らはコードを表示するために必要な言った:

#!/usr/bin/env python 
# -*- coding: UTF8 -*- 
topo1 = 0 
topo2 = 0 
print("This program helps compare two players: ") 
print("It only uses that player's stats from the previous two years to determine their worth in fantasy baseball") 
def complay1(): 
    global topo1 
    print("Enter in the first player's stats below") 
    homerun = input("Enter in the player's home run total from the most recent year: ") 
    sb = input("Enter in the player's stolen base total from the most recent year: ") 
    hit = input("Enter in the player's hit total from the most recent year: ") 
    walks = input("Enter in the player's walk total from the most recent year: ") 
    doubles = input("Enter in the player's doubles total from the most recent year: ") 
    rbi = input("Enter in the player's RBI total from the most recent year: ") 
    ba = input("Enter in the player's batting average from the most recent year, do not include a decimal point: ") 
    hitL = input("Enter in the player's hit total from the year before the most recent year: ") 
    homerunL = input("Enter in the player's home run total from the year before the most recent year: ") 
    age = input("Enter in the player's age: ") 
    gp = input("How many games did the player play last year?: ") 
    topo1 += int(homerun)*3 
    topo1 += int(sb)*2 
    topo1 += int(hit)/2.5 
    topo1 += int(walks)/4 
    topo1 += int(doubles) 
    topo1 += int(rbi)/3 
    topo1 += int(hitL)/15 
    topo1 += int(homerunL) 
    topo1/(int(gp)/4) 
    topo1 -= int(age) 
    topo1 += int(ba)/2 
    print(topo1, "is the total PLV+ for this player") 
def complay2(): 
    global topo2 
    print("Enter in the second player's stats below") 
    homerun = input("Enter in the player's home run total from the most recent year: ") 
    sb = input("Enter in the player's stolen base total from the most recent year: ") 
    hit = input("Enter in the player's hit total from the most recent year: ") 
    walks = input("Enter in the player's walk total from the most recent year: ") 
    doubles = input("Enter in the player's doubles total from the most recent year: ") 
    rbi = input("Enter in the player's RBI total from the most recent year: ") 
    ba = input("Enter in the player's batting average from the most recent year, do not include a decimal point: ") 
    hitL = input("Enter in the player's hit total from the year before the most recent year: ") 
    homerunL = input("Enter in the player's home run total from the year before the most recent year: ") 
    age = input("Enter in the player's age: ") 
    gp = input("How many games did the player play last year?: ") 
    topo2 += int(homerun)*3 
    topo2 += int(sb)*2 
    topo2 += int(hit)/2.5 
    topo2 += int(walks)/4 
    topo2 += int(doubles) 
    topo2 += int(ba)/2 
    topo2 += int(rbi)/3 
    topo2 += int(hitL)/15 
    topo2 += int(homerunL) 
    topo2/(int(gp)/4) 
    topo2 -= int(age) 
    topo1 += int(ba)/2 
    print(topo2, "is the total PLV+ for this player")  
complay1()  
complay2() 
if topo1 > topo2: 
    print("Player 1 is", ((topo1/topo2)*100)-100, "percent better") 
if topo2 > topo1: 
    print("Player 2 is", ((topo2/topo1)*100)-100, "percent better") 
+0

私はそれを実行し、topo1が定義されていないというエラーが表示されました。私はそれを見て、それが定義されているのを見なければならないでしょう。 – CoffeeRain

+0

'3to2.py'を実行してpython2と互換性のあるバージョンを取得しました – Daenyth

+0

問題は、complay2()に対してtopo2の代わりにtopo1を使用していたことでした。途中でプログラムの素晴らしいアイデア! – CoffeeRain

答えて

4

おそらくない、メジャーバージョンの変更には後方compatiblityを持っていません。

EDIT:コード例では、おそらく動作します。スクリプトで2と3の間で変更されたのは、printがPython 2の関数ではなく、print(x)がPython 2インタプリタのprint xと同じで、余分な角かっこが傷ついていないためです。

EDIT2:別の答えで言われているように、部門は分断されます。これはint/intがPython 2のintとPython 3のfloatになるためです。つまり、5/2はPython 2では2、Python 3では2.5です。from __future__ import divisionはこれを修正します。

2

それは、コードを見ずが完全特定することは不可能だが、それは極めてまれ動作するようになって、2.xと3.xの間の変更のたくさんがありました。

EDIT:

部門はそれを破るだろう。最上部にfrom __future__ import divisionと記入してください。また、raw_inputが存在することを確認し、inputに割り当てます。

+0

私はコードアップ! – Billjk

0

実行可能ファイルとはどういう意味ですか? Python実行可能ファイルの私の考えは、pythonがバンドルされているので、エンドユーザーは実行するためにPythonをインストールする必要はありません。

あなたが掲示したコードを見ると.pyだけであれば、互換性があります。

+0

私はちょうど拡張子なしで 'ファイル名'として、pythonファイルを保存したので、ターミナルで実行されます... – Billjk

関連する問題