简体   繁体   中英

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

When test running use 30 for air temp., and 44 for mph.

This code's loop only generates the same line of code which is this. I want it to be different for each line. How do I do this?

    `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()`

results from this code:

`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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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