当我运行代码时,输出对齐不准确,

2024-05-14 05:40:37 发布

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

from math import *

import numpy

element = {"1111":"The way", "1110":"Tail of the Dragon","1101":"The Boy","1100": "The Lesser Fortune","1011":"The Girl","1010":"Loss","1001":"The Prison","1000":"Joy","0111":"Head of the Dragon","0110":"The Conjuction","0101":"Gain","0100":"Red","0011":"Greater Fortune","0010":"White","0001":"Sorrow","0000":"People"}

z_array =[ ]

asia=["Life","Riches","Brothers","Father","Sons","Health","Spouse","Death","Journeys","Kings", "Good Fortune","Prison","Witness 1","Witness 2","Judge","Reconciler"]
for b in range(16):

    first =str(input(""))
    z_array.append(first)
    
    
europe_country =["",z_array[10],z_array[9],z_array[8],z_array[7],z_array[3],z_array[2],z_array[1],z_array[0],z_array[12],z_array[11],z_array[5],z_array[4],z_array[13],z_array[6],
z_array[14],z_array[15],]

print("House"+"\t"+"\t"+"Name"+"\t"+"\t"+"Symbol")
for b in range(1,17):

     asia1 = str(asia[b-1])
     country = "street"
     if len(asia1)>=8:
         print(str(b)+"\t"+"\t"+str(asia[b-1])+"\t"+str(element[europe_country[b]]))
     else:
         print(str(b)+"\t"+"\t"+str(asia[b-1])+"\t"+"\t"+str(element[europe_country[b]]))

当我尝试运行脚本时,输出对齐不准确,请帮助我修复此问题

我已经在上面添加了我的代码

谢谢


Tags: oftheimportelementarraycountryprintfortune
1条回答
网友
1楼 · 发布于 2024-05-14 05:40:37

我对上面的代码做了一些小改动,但这些都不是必需的。如果我不做这些改变,那么也没有问题。我在运行代码时传递下面的输入

1111
1101
1010
1000
1010
1110
0001
0101
0011
0101
0000
1111
1110
0001
1010
0101

下面我得到的输出是正确的格式,我想

House           Name            Symbol
1               Life            People
2               Riches          Gain
3               Brothers        Greater Fortune
4               Father          Gain
5               Sons            Joy
6               Health          Loss
7               Spouse          The Boy
8               Death           The way
9               Journeys        Tail of the Dragon
10              Kings           The way
11              Good Fortune    Tail of the Dragon
12              Prison          Loss
13              Witness 1       Sorrow
14              Witness 2       Sorrow
15              Judge           Loss
16              Reconciler      Gain

如果上述格式不可接受,请传递上述输入,并让我知道您的预期输出。这样我才能帮助你

相关问题 更多 >