假设第 1 个人有一个用 Python 3.x 编写的 python 可执行文件 (mac)。人 1 将所述文件发送给人 2,后者也有一台 mac,但只有 Python 2.6.1。当第 2 个人运行该文件时,它会起作用吗?
有人说他们需要看代码,所以:
#!/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")
最佳答案
可能不是,主要版本更改没有向后兼容性。
编辑:对于您的代码示例,它可能有效。脚本中 2 和 3 之间唯一发生变化的是 print 不是 Python 2 中的函数,这并不重要,因为 print(x) 与 Python 2 解释器的 print x 相同,额外的括号不会造成伤害。
EDIT2:正如另一个答案所说, split 也会破裂。这是因为 int/int 将在 Python 2 中生成一个 int,在 Python 3 中生成一个 float 。这意味着 5/2
在 Python 2 中为 2,在 Python 3 中为 2.5。来自 __future__导入部门
解决了这个问题。
关于在早期版本上运行的 Python 可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9674283/