I am currently working on a project and I need help on converting a list to a table. I have figured it out one way but there has to be a shorter and a cleaner way of doing it an
this code output equals your code output :)
sales_persons_list = [input('What is the name of the sales person?: ') for i in range(5)]
print(sales_persons_list)
sales_amounts_list = [
float(input('How much did {} make in sales?:'.format(sales_persons_list[i]))) for i in range(len(sales_persons_list))]
print(sales_amounts_list)
print("%-15s %-15s" %("Salespeople","Sales Amount"))
for i in range(len(sales_amounts_list)):
print("%-15s %-15s" %(sales_persons_list[i],sales_amounts_list[i]))
print("%-15s %-15s" %("Totals", sum(sales_amounts_list)))
show list as table code:
print("%-15s %-15s" %("Salespeople","Sales Amount"))
for i in range(len(sales_amounts_list)):
print("%-15s %-15s"%(sales_persons_list[i],sales_amounts_list[i]))
print("%-15s %-15s" %("Totals", sum(sales_amounts_list)))
Salespeople Sales Amount
a 1222.0
aa 1111.0
aaa 2222.0
aaaaa 3333.0
aaaaaa 1133.0
Totals 9021.0