0
with open('value.csv', 'w') as f:
writer = csv.writer(f)


while time < stage1_burn_time:
# Calculate update simulation variables based on current values:
altitude = altitude + (velocity * delta_t)
acceleration = (thrust(altitude, stage1_thrust_sl, stage1_thrust_vac) / mass) - gravity
velocity = velocity + (acceleration * delta_t)
mass = mass - burn_rate * delta_t
time = time + delta_t
writer.writerow(velocity')
writer.writerow('altitude')
writer.writerow('mass')

This is part of the code, what I want to do is to record the values as a line of comma-separated values in a CSV file, and I got a error message Error: iterable expected, not float

1 Answer 1

1
import csv

with open('values.csv', mode='w') as values_file:
    values_writer = csv.writer(values_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)

    values_writer.writerow(['velocity1', 'Altitude1', 'Mass1'])
    values_writer.writerow(['velocity2', 'Altitude2', 'Mass2'])

Reference: https://realpython.com/python-csv/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.