在早期版本上运行的Python可执行文件

2024-06-28 11:17:04 发布

您现在位置:Python中文网/ 问答频道 /正文

假设person1有一个用python3.x编写的python可执行文件(mac),person1将该文件发送给person2,person2也有mac,但只有python2.6.1。当Person 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")

Tags: theinfrommostinputyearinttotal
3条回答

你说的可执行文件是什么意思?我对python可执行文件的想法是python被捆绑在其中,这样最终用户就不需要安装python来运行它。你知道吗

如果你的意思只是.py,看看你发布的代码,它看起来是兼容的。你知道吗

在没有看到代码的情况下是不可能完全确定的,但是在2.x和3.x之间有很多变化,这使得它不太可能工作。你知道吗

编辑:

部门会打破它的。把from __future__ import division放在最上面。另外,检查raw_input是否存在,将其分配给input。你知道吗

可能不是,主要版本更改没有向后兼容性。你知道吗

编辑:对于您的代码示例,它可能有效。脚本中2和3之间唯一的变化是print不是python2中的函数,这一点并不重要,因为print(x)与python2解释器中的print x相同,额外的括号不会有任何影响。你知道吗

EDIT2:正如另一个回答中所说的那样,分歧也将破裂。这是因为int/int将导致python2中的int和python3中的float。这意味着5 / 2在python2中是2,在python3中是2.5。from __future__ import division解决了这个问题。你知道吗

相关问题 更多 >