I have an error in my program

Hi,

Here is the exercise I have to do:

So your program will start by assigning the number of guests to a variable (with name) n. Then, it will calculate the quantities (in grams or units) of each ingredient that it will store in three other variables: eggs, chocolate and sugar_vanilla.
Each of these quantities will be, as in the previous activity, truncated to the nearest unit.

This is my program :
def nombre(people):
e = int(egg)
egg=(3/4people)
c = int(chocolate)
chocolate=(100/4
people)
s = int(sugar)
sugar=(1/4*people)
return str(e) + " egg " + str(c) + " gramme " + str(s) + " gramme "
print(nombre(7))

But I have an error :
Traceback (most recent call last):

File “”, line 1, in
File “”, line 2, in nombre

UnboundLocalError: local variable ‘egg’ referenced before assignment

Thank you !

Your code does:

e = int(egg)

but it hasn’t set egg yet; it doesn’t do that until the next line.

Also, please wrap any code in triple backticks to preserve the formatting:

```
if True:
    print('Hello world!')
```

n is nowhere to be seen in this code

How quantities of each ingredient should be calculated?

For 4 people it is 100 g of chocolate, 1 sachet of vanilla sugar and 3 eggs

but now I have a new error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 6, in nombre
TypeError: unsupported operand type(s) for *: 'float' and 'function'

It always good to start from the beginning:

How it should be done? Simply assigning or asking for user input:

>>> n = 5    
>>> n = input("Enter number of guests: ")
Enter number of guests: 1
>>> n
'1'

If this is working as expected and meets exercise requirements move on to the next subproblem.

What’s on line 6 in 'nombre? According to the traceback, you’re multiplying 2 things together and the second thing is (the name of) a function.

If you need help with errors, please do this:

  • Store your program to a file. Let’s say food_storage.py
  • Execute the program from a terminal by giving the file name as a parameter to the Python interpreter:
    python3 food_storage.py
    Depending on your platform and the way Python was installed the command could be: python3, python or py. This way of running the program will give a better traceback.
  • Show both the current program and the session in the terminal - including the start of the program and the complete traceback.