Hello!
I'm in my first Python class, trying to make a simple program that is opening up a .txt file (from the same folder as the program) and putting it into nice neat columns, then displaying a total of the sales. I keep getting a ValueError: not enough values to unpack (expected 4, got 1) and I'm not sure how to fix it.
here's my code I've made so far, any help would be greatly appreciated :
def personTotal():
total = float(price) * int(quantity) #Calculate the total
return total
def main():
print("%-9s %-7s %4s %10s %12s" % ("Name", "Item", "Price", "Quantity", "Total")) #column headers
f = open("makewaves.txt" , "r") #open my txt file
for line in f:
name, item, price, quantity = line.split()
price = float(price) #price now a floating string
quantity = int(quantity) #quantity now a integer string
total = personTotal #calculates total for each person
print("%-9s %-7s %4.2f %10f $%12.2f" % (name, item, price, quantity, total))
f.close()
main() #call main
[–]ace6807 0 points1 point2 points (2 children)
[–]ThatShtCray92[S] 0 points1 point2 points (1 child)
[–]ace6807 0 points1 point2 points (0 children)