簡體   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