Lucas, you’re returning the error of name ' ' is not defined
, because the variables were not defined in the function media()
Note that you have defined the variables n1
, n2
, n3
and opcao
in the body of function notas()
, that is, they are with the local scope and therefore the function media()
not the 'vision'
One way to solve this would be to define the variables as global:
def notas():
global n1,n2,n3
opcao = 0
while opcao != 5:
n1 = int(input("Digite sua nota 1 :"))
n2 = int(input("Digite sua nota 2 :"))
n3 = int(input("Digite sua nota 3 :"))
opcao = input("Deseja sair?")
return opcao
def media():
media = (n1+n2+n3) / 3
print(" Sua media é {}",media)
notas()
media()
Note: I have not made any improvement in your code, but there is possibility to do several!
Because you are a beginner in Python, I advise you to study the following questions:
To understand what is Python scope:
How is a block of scope identified in a language like Python?
To understand the concept of global in Python:
Python functions-Global and local variables
What’s the difference between global and nonlocal in Python?