N
N
Natalia2020-08-10 13:56:13
Python
Natalia, 2020-08-10 13:56:13

Why does the NameError: name 'age' is not defined error occur?

The code

def user_spisok(name, age):
 for names in name:
    print("\nHello,"+ name.title())
print("\ How are old you ? ")
for ages in age :
 print(" My age" + "is" + age)
spisok ('eva', age=13)
user_spisok(spisok)

Mistake
for ages in age :
NameError: name 'age' is not defined

I don't understand why he doesn't see his age.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SKEPTIC, 2020-08-10
Kolins @snackli17

The code must be wrapped with the appropriate tag in the question. It is not clear where you have indents and so on.

def user_spisok(names, ages): 
    for i in range(len(names)):
        print(f"Это {names[i]}, ей {ages[i]} лет")
names = ['eva']
ages = [12]
user_spisok(names, ages)

S
Sergey Tikhonov, 2020-08-10
@tumbler

Indentation in python is meaningful, separating blocks from each other. Your code is clearly not doing what it was intended to do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question