【问题标题】:Compiling python code via Terminal (Mac OS)通过终端编译python代码(Mac OS)
【发布时间】:2018-04-21 17:15:24
【问题描述】:

我正在编写一个代码来分析大富翁的数学,我认为它很好,然后我保存它,然后我运行终端。

python Monopoly.py

python3 Monopoly.py

这两个命令都没有产生输出。没有警告也没有错误。问题出在哪里?

这是整个代码。我试图一次又一次地看它。以前是手写的,觉得还行。

输出中没有错误,只是什么都没有,就像它已经准备好运行一样。

def monop(finish_order=6,games_order=3):

finish = 10**finish_order
games = 10**games_order

import random
from random import shuffle

squares = []

while len(squares) < 40:
    squares.append(0)

# roll values are values from a six by six grid for all dice rolls
rollvalues = [2,3,4,5,6,7,3,4,5,6,7,8,4,5,6,7,8,9,5,6,7,8,9,10,6,7,8,9,10,11,7,8,9,10,11,12]

games_finished = 0

while games_finished < games:

    master_chest = [0,40,40,40,40,10,40,40,40,40,40,40,40,40,40,40]
    chest = [i for i in master_chest]
    shuffle(chest)

    master_chance = [0,24,11,'U','R',40,40,'B',10,40,40,5,39,40,40,40]
    chance = [i for i in master_chance]
    shuffle(chance)

    doubles = 0

    position = 0

    gos = 0

    while gos < finish:

        diceroll = int(36*random.random())

        if diceroll in [0,7,14,21,28,35]:    # these are the dice index values for double rolls
            doubles += 1
        else:
            doubles = 0
        if doubles >= 3:
            position = 10
        else:

            position = (position + rollvalues[diceroll])%40

            if position in [7,22,33]:  # Chance
                chance_card = chance.pop(0)
                if len(chance) == 0:
                    chance = [i for i in master_chance]
                    shuffle(chance)
                if chance_card != 40:

                    if isinstance(chance_card,int):
                        position = chance_card
                    elif chance_card == 'U':
                        while position not in [12,28]:
                            position = (position + 1)%40
                    elif chance_card == 'R':
                        while position not in [5,15,25,35]:
                            position = (position + 1)%40
                    elif chance_card == 'B':
                        position = position - 3

            elif position in [2,17]:  # Community Chest
                chest_card = chest.pop(0)
                if len(chest) == 0:
                    chest = [i for i in master_chest]
                    shuffle(chest)
                if chest_card != 40:
                    position = chest_card

            if position == 30: # Go to jail
                position = 10


        squares.insert(position,(squares.pop(position)+1))

        gos += 1

    games_finished += 1


return squares

【问题讨论】:

  • 看起来你的文件只是有一个方法没有在文件中的任何地方被调用..所以它只是运行完成而不向控制台打印任何内容..在第一行有一个print "hello world"文件并检查您在运行文件时是否看到它注意:python filename.py 是运行它的正确方法

标签: python python-3.x terminal compilation


【解决方案1】:

python filename.py 是从终端运行文件的正确方法。

尝试在您的文件中添加 print "" 语句以测试它是否有效

【讨论】:

  • 我在程序的开头加了一个,它做到了。
  • 酷..看起来python在你的机器上运行良好然后..在你的程序结束时调用你的函数来检查它的行为。 monop()
猜你喜欢
  • 2015-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-05
  • 2015-11-18
  • 2013-12-18
  • 2013-01-06
相关资源
最近更新 更多