In: Computer Science
A customer comes into a grocery store and buys 8 items. Write a PYTHON program that prompts the user for the name of the item AND the price of each item, and then simply displays whatever the user typed in on the screen nicely formatted.
Prorgam:
name_array = list()
price_array = list()
for x in range(8):
name = input("Enter item name: ")
name_array.append(str(name))
price = input("Enter item price: ")
price_array.append(float(price))
print(" List of items and their prices")
for i in range(8):
print("Name:",name_array[i])
print("Price:$",price_array[i])
Output:
Process:
First take two arrays , or we can say lists where one will store name of item and other will store price of item
Here we have taken name_array to store name of item and price_array to store price of item
Now as we know we have 8 items we will take a for loop which will run in range of 1 to 8
In each iteration it will ask for name of item and then store this to name_array by using append function, also to mention here we are using type as str to store name
Similarly it will take price and will store in price_array and to store this we are using type float.
Now to print the list we will use for loop and the print the
values using index location traced by loop counter i.