We are doing a fruit stand project in python and I have the

We are doing a fruit stand project in python and I have the first 2 parts done. I\'m having trouble with the third part. This is what I have for the first 2 parts which I know is right:

fruit_names = []
fruit_prices = []
fruit = raw_input(\"Enter a fruit name (or done): \")
while not (fruit == \"done\"):
fruit_names += [fruit]
fruit = raw_input(\"Enter a fruit name (or done): \")
for s in fruit_names:
price = float(raw_input(\"Enter the price for \" + s + \": \"))
fruit_prices += [price]

This is the instructions and example for the third part which we have to use indexes and a for loop:

Continue the fruit_stand.py program. It should calculate the total cost of an order. Use both the fruit list and price list from parts 1 and 2 to prompt the vendor for quantities of each fruit type, and then print out the total. Note each prompt should show both the fruit name and price.

The following is an example. Your program must first prompt the vendor for the fruit names and prices (see parts 1, 2) before prompting for the fruit quantities.

PS C:\\Users\\ssiva\\Desktop> python fruit_stand.py
Enter a fruit name (or done): Grapefruit
Enter a fruit name (or done): Cantaloupe
Enter a fruit name (or done): Orange
Enter a fruit name (or done): done

Enter the price for Grapefruit: 1.23
Enter the price for Cantaloupe: 2.50
Enter the price for Orange: 0.98

Grapefruit($1.23) Quantity: 3
Cantaloupe($2.5) Quantity: 2
Orange($0.98) Quantity: 10

Your total purchase is $18.49
PS C:\\Users\\ssiva\\Desktop>

If you could help me complete the third part, that would be awesome!!

Solution


fruit_names = []
fruit_prices = []


fruit = raw_input(\"Enter a fruit name (or done): \")
while not (fruit == \"done\"):
   fruit_names += [fruit]
   fruit = raw_input(\"Enter a fruit name (or done): \")

print \"\"
print \"\"

for s in fruit_names:
   price = float(raw_input(\"Enter the price for \" + s + \": \"))
   fruit_prices += [price]


total_price = 0.00

print \"\"
print \"\"

for i in range(len(fruit_names)):
   quantity = input(fruit_names[i] + \"($ \" + str(fruit_prices[i])+ \") Quantity: \")
   total_price += quantity*fruit_prices[i]

print \"Your total purchase is $\", total_price

We are doing a fruit stand project in python and I have the first 2 parts done. I\'m having trouble with the third part. This is what I have for the first 2 par
We are doing a fruit stand project in python and I have the first 2 parts done. I\'m having trouble with the third part. This is what I have for the first 2 par

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site