【问题标题】:Schedule Generator in python [duplicate]python中的计划生成器[重复]
【发布时间】:2021-12-28 07:48:39
【问题描述】:

Example Table

我想在 python 中制作一个程序,从用户那里接收服装号码(应该是 4、8、16、32 等 2 的幂...),然后程序开始像表格内容一样输出(链接在 UP 中)(n 支球队在 (n-1) 周内的比赛时间表,而且我们将有 n(n-1) 场比赛)。 谢谢。

【问题讨论】:

  • 欢迎来到 Stack Overflow。请不要发布示例链接,但请在您的问题中包含示例。
  • 另外,从你的问题来看,我不确定你想要达到什么目的。你能发布一个最小的可重复的例子吗? stackoverflow.com/help/minimal-reproducible-example我们会更容易提供帮助
  • 你尝试了什么?你的代码在哪里?

标签: python scheduling


【解决方案1】:

我用这段代码制作了表格的框架,但我的算法仍然有问题(用于制作比赛时间表)。

import math
from tabulate import tabulate
def is_power_of_two(team_num):
    return (math.ceil(math.log2(team_num)) == math.floor(math.log2(team_num)))
team_num_check = False
while (team_num_check == False):
       team_num = int(input('How many teams does this leage have ?\n'))
       if(is_power_of_two(team_num)):
           team_num_check = True
       else:
            print("Enter a valid number due to rules of league.")
week_num = (team_num - 1)
week_counter = 1
team_counter = 0
table = []
while team_counter <= team_num:
      table.append([team_counter])
      while week_counter <= week_num:
           table[team_counter].append(week_counter)
           week_counter+=1
      team_counter+=1
print(tabulate(table,tablefmt="github"))

【讨论】:

    【解决方案2】:

    您可以在此处使用 tabulate 模块:

    1. 在终端输入pip install tabulate。

    2. 这段代码可以工作:

       import math
       from tabulate import tabulate
      
       costume_number = int(input("Enter Costume number"))
       try:
           if math.log(costume_number, 2).is_integer():
               table_list = [["", "week", "1", "2", "3", "4", "5", "6"], ["team", "1", "2", "3", "4", "5", "6", "7"], []] #etc.. please continue writing whatever the data is.
               print(tabulate(table_list))
       except TypeError:
           print(costume_number + " is not a costume number.")
      

    【讨论】:

    • 但是...问题是如何生成数据来填充表格,而不仅仅是将其打印为表格...您没有回答问题的主要部分...
    猜你喜欢
    • 2019-04-13
    • 2017-05-30
    • 1970-01-01
    • 2014-01-06
    • 2020-07-04
    • 2016-04-20
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    相关资源
    最近更新 更多