试运行时,使用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`
答案 0 :(得分:0)
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()