Python NameError: name ' ' is not defined [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i am inputting simple code into IDLE but it keeps telling me after I run the simple program that a word to check how many vowels is not defined.
def search4vowels(word):
'''Return a boolean bassed on any vowels found.'''
vowels = set('aeiou')
return vowels.intersection(set(word))
Error Message
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
gal
NameError: name '' is not defined

I think you call your function like this:
search4vowels(gal).
Try calling it like this: search4vowels("gal").
You have to enclose strings in quotes, otherwise python is looking for a variable called gal (In your example).
gal is not defined==>Error

Related

Does if (None in string) return true or false? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I need to check for the occurrence of a value from a dictionary in a string. However some of those values may be None. If the value is None, will the condition return true or false, that is, will the 'None' value be found in the string?
This condition is part of an if statement with multiple conditions that are put together with 'and' and 'or' operators, and hence I can't simply check if the value is None, or separate it and do another if within the main condition. I don't want to implement the alternative of two separate conditions and statements unless it's absolutely necessary.
Neither, it will fail. This is verifiable with a 10 second REPL.
>>> None in 'some string'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand, not NoneType

Python problem can't run module and output problem [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I write code which will output some data file, but I got error and have no idea what is wrong already looking for 2 hours (you know how is it :) )
import binascii
import sys
import time
url12 = "my win dir for file"
def toHex(s):
1st = []
for ch in s:
hv = hex(ord(ch)).replace('0x', '')
if len(hv) == 1:
1st.append(hv)
return reduce(lambda x,y:x+y, 1st)
url = toHex(url12)
.......etc.
debug output:
Traceback (most recent call last):
File "C:\Users\RED\Desktop\builder\builderUpdate.py", line 22, in <module>
url = toHex(url12)
File "C:\Users\RED\Desktop\builder\builderUpdate.py", line 20, in toHex
return reduce(lambda x,y:x+y, lst)
NameError: name 'reduce' is not defined
In Python 2, reduce was a built-in function. In Python 3, you have to import it from functools
That's why you're getting an error
Also, the empty list in your function can't begin with a number otherwise you get a syntax error. It can contain numbers but should start with an underscore or a letter

what is my mistake in the code and why is that error for? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
So basically I have to write a code which tells the user to input numbers (as variables I named them number1, number2, number3 ...) until I get the answer of zero once you add each number that they inputted then which the sum is equal to zero I should print how many numbers they inputted so the answer they got was zero, now the main thing is that I know how to write that code but there is an error that I get:
Traceback (most recent call last):
File "Solution.py", line 13, in <module>
sys.exit()
NameError: name 'sys' is not defined
Maybe try using
from sys import *
and just use exit(0) when you want to sys.exit()

Python: most recent call last error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Can't understand the error in this as the brackets are as per directions
mean=df["Normalized-losses"].mean()
Traceback (most recent call last):
File "C:\Users\Aarushi Goyal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\nanops.py", line 822, in _ensure_numeric
x = float(x)
Please provide solution
Try converting the column into numeric using
pd.to_numeric(df['Normalized-losses'], errors = 'coerce')
Then try:
mean = df['Normalized-losses'].mean()
You can also use:
mean = df.loc[:, 'Normalized-losses'].mean()
If it doesn't help do provide more info regarding the error.
I think the variable "Normalized-losses" would be a non-numerical type variable.
Try pandas dtypes method to check data type:
df.dtypes
If its non-numerical then use astype() method to change the data type.

Why will this function not open my file? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
def open_file(filename):
file_open= open(filename,"r")
return file_open
When I try and call the function I get the following results:
>>> open_file(random.txt)
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
open_file(random.txt)
NameError: name 'random' is not defined
try
open_file('random.txt')
Strings in Python need to be quoted.
random is being interpreted as an object, and is undefined.
You forgot quotes:
open_file('random.txt')
python thinks random is an object, which obviously you didn't define. The quotes make it a string.
you just need to input the filename as a string; here's how it must be done:
>>> open_file('random.txt')
note that your function works just fine, all you need to do is call it properly.

Categories