10

これは私の最初のPythonプログラムであり、スタックオーバーフローに関する最初の質問です。そのため、コードが混乱している場合や、質問の形式が正しくない場合は、お詫び申し上げます。

すでに印刷しているのと同じ行を印刷したいのですが、各フロートはその値に基づいて異なる色にする必要があります。(具体的>.7には緑、.7<赤)これを行うための最良の方法は何ですか?

oreName=[#string names]

#escape char? I know there has to be a better way than this
#but this is the best ive come up with as the escape char didnt
#work the way I thought it should for '%'
char = '%'

netProfitBroker=[
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]]

##code that populates netProfitBroker

def printOutput(array):
  "this prints all of the lines"
  for i in range(0,10):
    print oreName[i]+"=   %.3f \t 5"%(array[0][i])+char+"=%.3f \t10"%(array[1][i])+char+"=%.3f"%(array[2][i])    


print "\nnet profit brokered"
printOutput(netProfitBroker)

出力は次のようになります:(ここに出力をコピーしたときに、空白のフォーマットの一部またはすべてが失われました)

net profit brokered

Veldspar   =   0.234     5%=0.340   10%=-0.017
Scordite   =   0.752     5%=0.297   10%=0.259
Pyroxeres  =   0.406     5%=1.612   10%=2.483
Plagioclase=   1.078     5%=0.103   10%=1.780
Omber      =   -7.120    5%=5.416   10%=4.612
Kernite    =   -10.822   5%=15.366  10%=6.626
Jaspet     =   17.772    5%=49.278  10%=62.380
Hemorphite =   -35.431   5%=82.912  10%=141.027
Gneiss     =   8.086     5%=-4638.549   10%=-3610.570
Arkonor    =   349.867   5%=-545.284    10%=-340.298

基本的に:

"ore name=" arrayVal1 "5%="arrayVal2 "10%="arrayVal3

すべての配列値は小数点以下3桁まで出力する必要があります。

4

1 に答える 1