How i over come with name error in python [duplicate] - python

This question already has answers here:
NameError: name 'raw_input' is not defined [duplicate]
(1 answer)
How do I use raw_input in Python 3?
(9 answers)
Closed 5 years ago.
i wrote following code but during run its gives name error in 'raw_input' please help me to out of this
my code is:fname = raw_input('enter a file name: ')
print (fname)
Error is= name error:name 'raw_input'is not define

raw_input on python 3+ is now just input()
fname = input('Enter a file name: ')
print(fname)

Related

Have this error (name 'raw_input' is not defined) [duplicate]

This question already has answers here:
How do I use raw_input in Python 3?
(9 answers)
NameError: name 'raw_input' is not defined [duplicate]
(1 answer)
Closed 3 years ago.
hae....my program keeps showing name 'raw_input' is not defined whenever i use a raw_input.
i.e
input1 = raw_input('Enter your number ')
then the error name 'raw_input' is not defined pops up...please help fix this.
thnks
Use input('Enter your number ') instead.
raw_input() is Python 2.x syntax.
raw_input() was renamed to input()
From What’s New In Python 3.0.

Python program giving error for raw_input() [duplicate]

This question already has answers here:
How do I use raw_input in Python 3?
(9 answers)
Closed 3 years ago.
Is there any way of getting string input from user, other than raw-input, as that generates an error in my python program?
choice = raw_input("Do you want to convert from celcius to farenheit?")
NameError: name 'raw_input' is not defined
raw_input is not working because you are using Python 3. If you want raw_input, try downgrading to use Python 2 instead.
Alternatively, if you must use Python 3, you can use the function input like so:
name = input("Enter your name: ")

python variable is not defined using print function [duplicate]

This question already has answers here:
input() error - NameError: name '...' is not defined
(15 answers)
Closed 4 years ago.
After running the below code, python prompt error and tell me name "tony" is not defined.
print('Hello Sam, this is Javis')
#let user enter their name, "nm" being the variable
nm = input('Please tell me your name => ')
print('It is definitely nice to meet you',nm,'!')
I input name as "Tony"
What did i do wrong?
You need to use "+" Instead of commas since you're adding the input. like so:
print('It is definitely nice to meet you '+nm+'!')

How can my input to a variable not be defined within python [duplicate]

This question already has answers here:
"NameError: name '' is not defined" after user input in Python [duplicate]
(3 answers)
Closed 5 years ago.
Im making a program that will ask the user for their first name and surname.
This data is then saved to a .txt file.
I understand that the coding is basic and easy to understand but just recently this code has decided to not work.
file1 = open("document.txt",'w')
firstname = input("What is your first name?")
secondname = input("what is you second name?")
file1 = open ('document.txt','w')
file1.write (firstname + secondname)
newfile.close()
I am given the following error when running this piece of code
You have to use raw_input in order to get a string in Python 2. input is evaluating the user input, seeing the variable name which is not defined.

Can someone help me with this syntax error print name.find('s')? [duplicate]

This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 6 years ago.
I am using python 3.5.1. I have a variable called name and the value assigned is sarah. I get a syntax error when I type print name.find('s'). What am I doing wrong?
In Python 3, print() is a function and requires parentheses:
print(name.find('s'))

Categories

Resources