我很难将一组来自循环的数字写入文件中的单独行。当我想要的是来自循环每一行的数据时,我现在拥有的代码将打印 5 行完全相同的数据。我希望这是有道理的。
mass_of_rider_kg = float(input('input mass of rider in kilograms:'))
mass_of_bike_kg = float(input('input mass of bike in kilograms:'))
velocity_in_ms = float(input('input velocity in meters per second:'))
coefficient_of_drafting = float(input('input coefficient of drafting:'))
a = mass_of_rider_kg
while a < mass_of_rider_kg+20:
a = a + 4
pAir = .18*coefficient_of_drafting*(velocity_in_ms**3)
pRoll = .001*9.8*(a+mass_of_bike_kg)*velocity_in_ms
pSec = pAir+pRoll
print(pSec)
myfile=open('BikeOutput.txt','w')
for x in range(1,6):
myfile.write('data:' + str(a) + str(mass_of_bike_kg) + str(velocity_in_ms) + str(coefficient_of_drafting) + str(pSec) + "\n")
myfile.close()