How to simplify function called print_monthly_expense, that receives the name of the month and the hours

0 votes
asked Mar 14 by anonymous
june_hours = 243
june_cost = june_hours * 0.65
print("In June we spent: " + str(june_cost))

july_hours = 325
july_cost = july_hours * 0.65
print("In July we spent: " + str(july_cost))

august_hours = 298
august_cost = august_hours * 0.65
print("In August we spent: " + str(august_cost))

1 Answer

0 votes
answered Mar 20 by (140 points)
class Monthly_expense:
    def __init__ (self,hours,cost,month):
        self.hours=hours
        self.cost=cost
        self.month=month
        
        cost= hours* 0.65
       
        print("In "+month+" we spent: " + str(cost))
        
#Start Entry
Start=input("Start data entry (Y/N):")

while Start.upper() != "N":
    
    month=input("Enter month :")
    hours=int(input("Please enter hours :"))
    cost=0
    monthly_exp =Monthly_expense(hours,cost,month)
    
    cont=input("Continue entry(Y/N) :")
    
    if cont.upper() == "N" :
        break
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...