简体   繁体   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?

When test running use 30 for air temp., and 44 for mph. 进行测试运行时,请使用30摄氏度和44英里/小时的气温。

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

暂无
暂无

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

相关问题 如何在 Python 中打印出 for 循环的每次迭代? - How do I print out each iteration of the for loop in Python? 如何在每次 [Python 3.x] 的不同输出的同一行(shell 或窗口)中重新打印 2D 数组或多个输出? - How can I reprint 2D array or multiple outputs in the same line of (shell or window) with different output each time [Python 3.x]? 如何在 Python 3.x 中逐行打印网页 - How can I print a webpage line by line in Python 3.x 如何在 python 的同一行上使用 for 循环打印? - How to printing using for loop on same line in python? 我如何在 python 的 while 循环中逐行打印 a.txt 文件中的每一行 - How do i print each line in a .txt file one by one in a while loop in python 如何遍历文件的每一行并打印出包含彼此相邻的两个元音的任何单词? - How do I loop through each line of a file and print out any words that contain two vowels next to each other? 刚开始学习 python; 当我使用列表推导时,为什么这个 for 循环的打印不同? 我如何使循环相同? - New to learning python; why is the print for this for-loop different when I use a list comprehension? how do i make the loop be the same? 如何使“ while”循环将循环的条件结果打印到一行(连接的)中? - How do I make a 'while' loop print the results of the loop's conditional into a single line(concatenated)? Python:从条件for循环中打印出结果 - Python: Printing out result from conditional for loop python while 循环打印每一行 - python while loop printing each line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM