Python-一行打印多个功能 - python

因此,在Google上进行搜索时,我发现的唯一想法就是将print()函数全部打印在一行中。我想做的是打印多个函数(例如def function1():)类型的函数。

if choice == "y":
      dice = input("What are the face values of the dice?")
      for c in dice:
        if c == "1":
          dot1()

我希望能够打印可能的dot2()或dot3()(如果选择的是同一行上的2或3)。那可能吗?现在dot1(),2和3看起来像:

def dot1():
  print()
  print(" * ")
  print()
  return()


def dot2():
  print("*")
  print()
  print("  *")
  return()


def dot3():
  print("*")
  print(" *")
  print("  *")
  return()

如果是这样,请告诉我!另外,如果您想要更多代码作为示例,请告诉我。这真是困扰我哈哈

参考方案

也许您正在尝试打印骰子面的点状图案?

def dot_pattern(c):  
    dice_repr = {1: '\n *\n\n',
             2: '*\n\n  *',
             3: '*\n *\n  *',
             4: '* *\n\n* *',
             5: '* *\n *\n* *',
             6: '* *\n* *\n* *'}  
    return dice_repr[c]

for c in range(1, 7):
    print(dot_pattern(c))
    print()

输出:

输出量

 *



*

  *

*
 *
  *

* *

* *

* *
 *
* *

* *
* *
* *

python JSON对象必须是str,bytes或bytearray,而不是'dict - python

在Python 3中,要加载以前保存的json,如下所示:json.dumps(dictionary)输出是这样的{"('Hello',)": 6, "('Hi',)": 5}当我使用json.loads({"('Hello',)": 6,…

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

Python:无法识别Pip命令 - python

这是我拍摄的屏幕截图。当我尝试在命令提示符下使用pip时,出现以下错误消息:pip无法识别为内部或外部命令,可操作程序或批处理文件。我已经检查了这个线程:How do I install pip on Windows?我所能找到的就是我必须将"C:\PythonX\Scripts"添加到我的类路径中,其中X代表python版本。如您在我的…

Python:使用两个列表进行字典 - python

如何使用python使用两个列表作为字典list_one_keys = ['key1', 'key2', 'key3', 'key4'] 嵌套列表:list_two_values = [['a1var1', 'a1var2', '…

Python:如何将有效的uuid从String转换为UUID? - python

我收到的数据是 { "name": "Unknown", "parent": "Uncategorized", "uuid": "06335e84-2872-4914-8c5d-3ed07d2a2f16" }, 我需要将uuid从Strin…