Make a .py file called fruitStorage.py. The script should asks
users for a fruit/vegetable and the count of those items that they
have, or “quit” to quit. Until the user enters quit, store the
fruit and their count in a list of tuples, of the form:
[(tomato, 5), (blueberry, 10), ….]
Duplicates should add the count to the already stored count.
When the user enters quit, print a report of the user’s input, with the following general appearance:
Produce, Count
tomato, 5
blueberry, 10
…
…
…
Average count per produce item: #
Total # of produce: #
Where total is the sum of counts and the average is the average count of produce per produce.
Make an edit of the first .py, called fruitDictionary. Perform the
same task as above, with the same output. The exact approach is up
to you. In a comment in the .py file, say which of the two
approaches you prefer and why.
code,indentation(as HomeworkLib editor doesn't support indentation in its editor) and test cases are provided below..please comment for any queries and don't forget to thumbs up if helped!
code:
#fruitStorage.py
ftupls=list()
flag=True
while(flag):
print("1.add a fruit/vegetable\n2.quit")
inp=int(input())
if(inp==1):
print("enter fruit/vegetable name")
fname=input()
print("enter fruit/vegetable count")
fcount=int(input())
ls=[item for item in ftupls if item[0] == fname]
if(ls==[]):
ftupls.append((fname,fcount))
else:
for i,(fruit, count) in enumerate(ftupls):
if(fruit==fname):
ftupls[i] = (fruit, count+fcount)
if(inp==2):
print("Produce,Count")
total=0
for tp in ftupls:
print("{},{}".format(tp[0],tp[1]))
total+=tp[1]
avg=total/len(ftupls)
print("Average count per produce item: {}".format(avg))
print("Total of produce: {}".format(total))
flag=False
indentation:
output:
code:
#fruitDictionary.py
fdicls=list()
flag=True
while(flag):
print("1.add a fruit/vegetable\n2.quit")
inp=int(input())
if(inp==1):
print("enter fruit/vegetable name")
fname=input()
print("enter fruit/vegetable count")
fcount=int(input())
if(any(fname in item for item in fdicls)):
for fd in fdicls:
for fruit,count in fd.items():
if(fruit==fname):
fd[fruit] = count+fcount
else:
fdicls.append({fname:fcount})
if(inp==2):
print("Produce,Count")
total=0
for fd in fdicls:
for fruit,count in fd.items():
print("{},{}".format(fruit,count))
total+=count
avg=total/len(fdicls)
print("Average count per produce item: {}".format(avg))
print("Total of produce: {}".format(total))
flag=False
indentation:
output:
#comment in any of the .py file provided this:
#i would prefer using dict for this problem as it makes accessing and manipulating values by keys easy
Make a .py file called fruitStorage.py. The script should asks users for a fruit/vegetable and the...
Create a Python script file called hw12.py. Add your name at the top as a comment, along with the class name and date. Ex. 1. a. Texting Shortcuts When people are texting, they use shortcuts for faster typing. Consider the following list of shortcuts: For example, the sentence "see you before class" can be written as "c u b4 class". To encode a text using these shortcuts, we need to perform a replace of the text on the left with...
Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.) 2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...