繁体   English   中英

循环保持打印出相同的结果? (python 3.x)如何在每行上打印具有不同结果的循环?

[英]loop keeps printing out same result? (python 3.x) How do I print a loop with different results on each line?

进行测试运行时,请使用30摄氏度和44英里/小时的气温。

该代码的循环仅生成与此相同的代码行。 我希望每一行都不同。 我该怎么做呢?

    `from math import *

def main():
    tempF = eval (input('Enter air temperature (F): '))
    startingVelocity = eval (input('Enter starting wind speed (mph): '))

    OldStyleWC = round(0.081 * (3.71*sqrt(startingVelocity) + 5.81 - 0.25 * startingVelocity) * (tempF - 91.4) + 91.4,1)
    NewStyleWC = round(35.74 + 0.6215 * tempF - 35.75 * (startingVelocity**0.16) + 0.4275 * tempF * (startingVelocity**0.16),1)
    Difference = round(OldStyleWC - NewStyleWC)

    print (' ')
    print ('Big Blue Wind Chill')
    print (' ')
    print ('Enter air temperature (F): ', startingVelocity)
    print ('Enter starting wind speed (mph): ', tempF)
    print (' ')
    print ('Temperature = ', tempF, 'degrees F')
    print(' ')
    print ('Wind Speed', 'Old Formula', 'New Formula', 'Difference', sep='\t')


    for velocity in range(startingVelocity, 90, 5):

        print(velocity, OldStyleWC, NewStyleWC, Difference, sep="              ")



main()`

此代码的结果:

`Wind Speed Old Formula New Formula Difference
44              -5.2              12.4              -18
49              -5.2              12.4              -18
54              -5.2              12.4              -18
59              -5.2              12.4              -18
64              -5.2              12.4              -18
69              -5.2              12.4              -18
74              -5.2              12.4              -18
79              -5.2              12.4              -18
84              -5.2              12.4              -18
89              -5.2              12.4              -18`
from math import *

def main():
    tempF = eval (input('Enter air temperature (F): '))
    startingVelocity = eval (input('Enter starting wind speed (mph): '))

    print (' ')
    print ('Big Blue Wind Chill')
    print (' ')
    print ('Enter air temperature (F): ', startingVelocity)
    print ('Enter starting wind speed (mph): ', tempF)
    print (' ')
    print ('Temperature = ', tempF, 'degrees F')
    print(' ')
    print ('Wind Speed', 'Old Formula', 'New Formula', 'Difference', sep='\t')


    for velocity in range(startingVelocity, 90, 5):
        OldStyleWC = round(0.081 * (3.71*sqrt(velocity) + 5.81 - 0.25 * velocity) * (tempF - 91.4) + 91.4,1)
        NewStyleWC = round(35.74 + 0.6215 * tempF - 35.75 * (velocity**0.16) + 0.4275 * tempF * (velocity**0.16),1)
        Difference = round(OldStyleWC - NewStyleWC)

        print(velocity, OldStyleWC, NewStyleWC, Difference, sep="              ")



main()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM