Computer Science, asked by shuklajaya35, 5 months ago

a) Find and write the output of the following python codes with trace table:
fruit ()
Fruits=["Apple","Banana", "Grapes","Apple", "Apple", "Banana", "apple")
for åndex 'in Fruits:
if index in fruit:
fruit[index]+=1
else:
fruit[index]=1
print(fruit)
print("There are", len(fruit),"fruits")​

Answers

Answered by john4750
5

Explanation:

Fruits=["Apple","Banana", "Grapes","Apple", "Apple", "Banana", "apple")

for åndex 'in Fruits:

if index in fruit:

fruit[index]+=1

else:

fruit[index]=1

print(fruit)

print("There are", len(fruit),"fruits")

plz mark me as brainleast

Answered by amankatiyar362
0

Answer:

{'Apple': 3, 'Banana': 2, 'Grapes': 1, 'apple': 1}

There are 4 fruits

Explanation:

Firstly fruit named empty dictionary created to store the fruits quantity.

Then we have list named Fruits which contain the name of fruits.

for operator iterates through the Fruits list and we give code two conditions, In first condition it checks the element name is present in fruit dictionary in the form of keys, if it true then it increment that key value by 1.

In second condition it checks the element is unique in dictionary and if it's true then it add that element in fruit dictionary as key and assigned value 1.

At last of the code we print the fruit dictionary and the length of the dictionary.

#SPJ3

Similar questions