0

I have to be able to calculate the revenu per month depending on the number of goats sold per month knowing that every month I sell 20% of the goats I had initially in January. When I try to calculate it through my price_list I can only get 400$ and not the 300$ for the corresponding months.

The variable d is there to know whether or not the month starts with a vowel. If it does d= "d'" and if not d="de".

I have been going at it for a week and can't seem to find a solution for neither of my two problems.

Help would be really appreciated !!!

goats=int(input("Enter the number of goats at the beginning of january :"))
 
 year= ["january","february","march","april","may","june","july","august","september","october","november","december"]
 vowels = "aeiouy"
 price_list = [400,400,400,400,300,300,300,300,300,300,400,400]
 d=""
 
 if goats >0:
 for month in range(len(year)):
 goats_left = int(goats*0.8)
 goats_sold = goats - goats_left
 goats = goats_left
 print("At the of the month of {0} {1} , we will have {2} goats left, monthly revenu: {3} $".format(d,year[month],goats,price_list[i]))
 else:
 print("The number entered is not valid {0}.format(goats))
 goats=int(input("Enter the number of goats at the beginning of january :"))
 
 
 
 
 print("\n")
 print("ANNUAL REVENUE ........................................................ :".format())
 print(goats_sold_list)
asked Oct 10, 2021 at 23:35
1
  • 3
    You have typos and undefined variables in your code. goats_sold_list is not defined. print("The number entered is not valid {0}.format(goats)) has a missing ". i in price_list[i] is not defined. For what do you use vowels? You never set d. Commented Oct 10, 2021 at 23:40

2 Answers 2

1

My first suggestion would be to use enumerate as a more pythonic way to iterate over your list and get it's index. I also don't understand your use of d anywhere so perhaps clarify how you intended it to be used.

Finally, l don't see i or goats_sold_list declared anywhere.

This should be a starting point for improvement:

goats = int(input("Enter the number of goats at the beginning of january :"))
 
year = ["january","february","march","april","may","june","july","august","september","october","november","december"]
vowels = "aeiou"
price_list = [400,400,400,400,300,300,300,300,300,300,400,400]
d=""
goats_sold_list = []
 
if goats >0:
 for index, month in enumerate(year):
 #int() always rounds down, i.e 0.8 goes to 0
 goats_left = int(goats*0.8)
 goats_sold = goats - goats_left
 goats = goats_left
 goats_sold_list.append(goats_sold)
 print("At the of the month of {0} {1} , we will have {2} goats left, monthly revenu: {3} $".format(d,month,goats,price_list[index]))
else:
 print("The number entered is not valid {0}.format(goats)")
 goats=int(input("Enter the number of goats at the beginning of january :"))
print("\n")
print("ANNUAL REVENUE ........................................................ :".format())
print(goats_sold_list)
answered Oct 10, 2021 at 23:58
Sign up to request clarification or add additional context in comments.

Comments

0

I don't see a definition for [i] in price_list[i], barring some outside definition, I think that should be price_list[month].

I don't see d being set at any point, you might need to have some line of code setting d to some value based on the first letter of the month.

answered Oct 10, 2021 at 23:52

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.