In python NameError: name ‘true’ is not defined. Did you mean: ‘True’? we face this error message when we misspell True (capital T) Booleans as true (small t), and then python shows this error message. If you want to fix this error just type True (capital T) instead of (small t), For more clarification see the below example.
Wrong Code
n = int(input("Check this number:"))
def prime(number):
for i in range(2, number):
is_prime = true
for i in range(2, number):
if number % i == 0:
is_prime = False
if is_prime:
print("It's a prime number.")
else:
print("It's not a prime number.")
prime(number = n)
Error Massage
Check this number:25
Traceback (most recent call last):
File "/home/kali/python/webproject/simple_projects/prime_number/main.py", line 17, in <module>
prime(number = n)
File "/home/kali/python/webproject/simple_projects/prime_number/main.py", line 7, in prime
is_prime = true
NameError: name 'true' is not defined. Did you mean: 'True'?
Wrong code line
is_prime = true
Correct code line
is_prime = True
- Wrong action: true (small t).
- Correct action: True (capital T)
Entire Correct Code line
n = int(input("Check this number:"))
def prime(number):
for i in range(2, number):
is_prime = True
for i in range(2, number):
if number % i == 0:
is_prime = False
if is_prime:
print("It's a prime number.")
else:
print("It's not a prime number.")
prime(number = n)
What is NameError: name ‘true’ is not defined. Did you mean: ‘True’?
In python, we face this error message when we misspell True (capital T) Booleans as true (small t), then python shows this error message.
How to fix NameError: name ‘true’ is not defined. Did you mean: ‘True’?
If you want to fix this error just type True (capital T) instead of (small t), For more clarification see the above example.
For more information Visit YouTube Channel.

