Hi community,
I’m new to python programming and my code has no errors but it will not run, please help.
import csv
def read_sales():
data=[]
with open('sales.csv','r') as sales_csv:
spreadsheet = csv.DictReader(sales_csv)
for row in spreadsheet:
data.append(row)
return data
def run():
data =read_sales()
sales=[]
for row in data:
sales = int(row['sales'])
total_sales=sum(sales)
print(f"Total sales:{total_sales}")
(run)
Hey @JoyceNhlengetwa, welcome to the community!
To call a function, you must put the parentheses after the function name like so:
run()
If this post solved your problem, please mark it as the solution so the thread can close.
5 Likes
As @QwertyQwerty88 mentioned above, simply append the line:
run()
to the bottom of the code. Your code should now be:
import csv
def read_sales():
data=[]
with open('sales.csv','r') as sales_csv:
spreadsheet = csv.DictReader(sales_csv)
for row in spreadsheet:
data.append(row)
return data
def run():
data =read_sales()
sales=[]
for row in data:
sales = int(row['sales'])
total_sales=sum(sales)
print(f"Total sales:{total_sales}")
run()
1 Like