如何将打印命令右对齐而不是另一个打印命令的底部对齐?

时间:2019-02-03 04:11:10

标签: python python-3.x python-2.7

我创建了一个计算风速的应用程序。它通过循环间隔startWS(用户输入的启动风速)和99来实现。理想情况下,它看起来像这样: Ideal run。但是,当我使用以下代码时:

import math
x=' '
print("Big Blue Wind Chill") 
print(x) 
airTemp=float(input("Enter air temperature (F): ")) 
startWS=eval(input("Enter starting wind speed (mph): ")) 
print(x)
print("Temperature = " + str(airTemp) + " degrees F") 
print(x) 
def Main(): 
    print("Wind Speed") 
    i=startWS
    for i in range(startWS,91):
        print(i) 
        i=i+1 
Main()    
def oldForumula():
    print("Old Formula") 
    i=startWS
    for i in range(startWS,91):
            old=round(0.081*(3.71*math.sqrt(i)+5.81-0.25*i)*(airTemp-91.4)+91.4)
            print(old) 
            i=i+1 
oldForumula()
def newForumula():
    print("New Formula") 
    i=startWS
    for i in range(startWS,91):
            new=round(35.74+0.6215*airTemp-35.75*(i**0.16)+0.4275*airTemp*(i**0.16))
            print(new) 
            i=i+1 
newForumula()      
def difference():
    print("Difference") 
    i=startWS
    for i in range(startWS,91):
            diff=round((0.081*(3.71*math.sqrt(i)+5.81-0.25*i)*(airTemp-91.4)+91.4)-(35.74+0.6215*airTemp-35.75*(i**0.16)+0.4275*airTemp*(i**0.16)),1)
            print(diff) 
            i=i+1 
difference() 

我最终得到的结果是,这些循环在垂直方向上依次排成一行,而不是通过彼此水平地运行来创建表。当我运行它时,它看起来像这样: When I run it part 1 When I run it part 2

如果您知道可以在其中的“风速”右侧而不是在“风速”右侧添加“旧配方”文本的肉类食品,那么如果您能告诉我,我将不胜感激。 / p>

编辑:这是我运行xashru的代码后发生的情况: xashru's code

1 个答案:

答案 0 :(得分:0)

您可以使用列表列表。首先填充列表,然后顺序打印每个条目。

entries = x = [[] for i in range(91-startWS)]
def Main(): 
    i=startWS
    for i in range(startWS,91):
        entries[i-startWS].append(i)
        i=i+1 
Main()    
def oldForumula():
    i=startWS
    for i in range(startWS,91):
            old=round(0.081*(3.71*math.sqrt(i)+5.81-0.25*i)*(airTemp-91.4)+91.4)
            entries[i-startWS].append(old)
            i=i+1 
oldForumula()
def newForumula():
    i=startWS
    for i in range(startWS,91):
            new=round(35.74+0.6215*airTemp-35.75*(i**0.16)+0.4275*airTemp*(i**0.16))
            #print(new) 
            entries[i-startWS].append(new)
            i=i+1 
newForumula()      
def difference():
    i=startWS
    for i in range(startWS,91):
            diff=round((0.081*(3.71*math.sqrt(i)+5.81-0.25*i)*(airTemp-91.4)+91.4)-(35.74+0.6215*airTemp-35.75*(i**0.16)+0.4275*airTemp*(i**0.16)),1)
            #print(diff) 
            entries[i-startWS].append(diff)
            i=i+1 
difference()

print('Wind Speed', 'Old Formula', 'New Formula', 'Difference', sep='\t')
for i in range(len(entries)):
    for j in range(4):
        print(entries[i][j], end='\t\t')
    print()