i want to create a list or a dictionary not sure which niether have worked so far
i need to convert text (user input) into numeric value and add them together
there are 4 possible answers
this is how i want it to work
each box contains fruit and are sold for differant prices
apple=25,oranges=35,pears=10,bananas=50,pineapple=40
totalprice=0
count=5
list = [box1,box2,box3,box4,box5,]
while count >0:
fruit=raw_input("what fruit is in ")(0)
count -=1
if fruit ==apples:
return "price 25"
totalprice=+25
i want this to run five times gathering the total price along the way
is there a away that whatever fruit they put in the corresponding value will be added to total price.
sorry if not explained very well new to programming
Firstly, it would make sense to use a
dictto store fruit name – > price.Then we create an empty list, and loop over the numbers from 1 to 5 (note that 6 isn’t included in the range)…
We then use
sumthat takes the inputs, and tries to look up the value infruits…Sample run:
Other things you could do are validate a fruit exists before appending it to
inputs– but this should be enough for you to work with for the moment.