python 3
A grocery store keeps track of the fruits it has sold. Currently it only tracks apples and bananas. Write a program that first asks the user to enter how many days he/she wants to record, then for each day prompts the user to enter the profit of selling apples and bananas respectively. The program should display the total profit made by selling the two fruits over all these days, and show which fruit -- apples or bananas -- makes more profit.
Sample input & output: (Prompt) Enter the number of days: (User enter) 2 (Prompt) Enter the profit for apples on Day 1: (User enter) 40 (Prompt) Enter the profit for bananas on Day 1: (User enter) 80 (Prompt) Enter the profit for apples on Day 2: (User enter) 60 (Prompt) Enter the profit for bananas on Day 2: (User enter) 40 (Output) The total profit (including both apples and bananas) is $ 220.0 (Output) Selling bananas makes more profit.
#take number of days from user
numberOfDays=int(input("Enter the number of days:"))
#assign totalprofit from banana and apple as zero
profitFromBananas=0
profitFromApples=0
#input daily profit from user for all days
for day in range(0,numberOfDays):
print("Enter the profit for apples on Day ",day+1)
dailyProfitApples=int(input())
print("Enter the profit for bananas on Day ",day+1)
dailyProfitBanana=int(input())
# adding to total profit
profitFromBananas=profitFromBananas+dailyProfitBanana
profitFromApples=profitFromApples+dailyProfitApples
# print total profit
totalProfit=profitFromApples+profitFromBananas
print("total profit (including both apples and bananas) is $", totalProfit)
#print which fruit makes more profit
if profitFromBananas>profitFromApples:
print("Selling bananas makes more profit.")
elif profitFromBananas<profitFromApples:
print("Selling apples makes more profit.")
else:
print("Selling apples and bananas makes equal profit.")
Get Answers For Free
Most questions answered within 1 hours.