I have the dataset about animal statistics. Where the cat_teeth, dog_teeth, horse_teeth, and these numfeet variables are all the integers.
print(“Cat”,sum(cat_teeth), cat_numfeet)
print(“Dog”,sum(dog_teeth), dog_numfeet)
print(“Horse”,sum(horse_teeth), horse_numfeet)
The output I am getting is:
Cat 38 4jj
Dog 21 4
Horse 28 4
I want that same output exported to the csv file where I have 3 columns as shown above delimited by the comma (,).
How do I achieve it?
import csv
with open(“results.csv”, “w”) as csvfile:
writer= csv.writer(csvfile)
writer.writerow(“Cat”,sum(cat_teeth), cat_numfeet))
writer.writerow(“Dog”,sum(dog_teeth), dog_numfeet)
writer.writerow(“Horse”,sum(horse_teeth), horse_numfeet)
This is not working.