Question: Python, I am working on a code which can be found below that when ever I enter banana then apple then cantaloupe it does not
Python, I am working on a code which can be found below that when ever I enter banana then apple then cantaloupe it does not include cantaloupe. Does anyone know what I am doing wrong?
fruit_list = []
empty_str = ''
print('Enter all the kinds of fruit and the weight in pounds of each of them')
print('hit "return" when done ')
entered_fruit = input('Enter fruit: ')
while entered_fruit != empty_str: num_pounds = int(input('Type in the number of pounds of ' + entered_fruit + ': '))
if len(fruit_list) == 0: fruit_list = [(entered_fruit, num_pounds)]
else: insert_index = 0 index = 0 location_found = False
while index
if fruit_list[index][0]
else: fruit_list.insert(index,(entered_fruit, num_pounds)) location_found = True entered_fruit = input(' Entered fruit and their weight: ')
print(fruit_list)
fruit-list [] = empty-str = '' print'Enter all the kinds of fruit and the weight in pounds of each of them' print('hit "return" when doneIn) entered_fruit inputC' Enter fruit:) while entered-fruit-empty-str: num.pounds-inutyihe number of pounds of * entered_fruit + ': ').) -0: [Centered-fruit, if len(fruit-list) fruit-list = num-pounds) else: insert-index = 0 index = 0 location-found = False while index len(fruit list) and not location_found: if fruit_list[index] [0]
Step by Step Solution
There are 3 Steps involved in it
The problem seems to be with how the new fruit input overwrites the previous input when hitting retu... View full answer
Get step-by-step solutions from verified subject matter experts
