Lists and arrays are a very powerful type of variable that can store large volumes of data. Once stored, the data can be easily manipulated using built-in functions such as sorting, counting, appending, and more.
The program below inputs data into lists and then uses that data:
fruit = []
initialstock = []
sold = []
instock = []
fruit.append(input("Enter the name of the 1st fruit: "))
fruit.append(input("Enter the name of the 2nd fruit: "))
print()
initialstock.append(input("Enter the amount of kg for "+fruit[0]+": "))
initialstock.append(input("Enter the amount of kg for "+fruit[1]+": "))
print()
sold.append(input("Enter the Kg that are sold for "+fruit[0]+": "))
sold.append(input("Enter the Kg that are sold for "+fruit[1]+": "))
print()
instock.append(float(initialstock[0]) - float(sold[0]))
instock.append(float(initialstock[1]) - float(sold[1]))
print("%-30s %15s %15s" % ("Fruit", fruit[0], fruit[1]))
print("%-30s %15.2f %15.2f" % ("Initial Stock - Kg", float(initialstock[0]), float(initialstock[1])))
print("%-30s %15.2f %15.2f" % ("Sold - Kg", float(sold[0]), float(sold[1])))
print("%-30s %15.2f %15.2f" % ("In Stocl - Kg", float(instock[0]), float(instock[1])))
Copy, paste, and run this code to get the output shown below:
