python variable is not defined using print function [duplicate] - python

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+'!')

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: ")

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.

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

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)

In Python input returned does not get detected by my if or elif statements skips straight to else statement, why? [duplicate]

This question already has answers here:
String comparison in Python: is vs. == [duplicate]
(4 answers)
Closed 6 years ago.
I am new to programming and using Python 3.5. When ever I run the following code it skips my if and elif statement and goes straight to else after entering input values that should run in the if or the elif lines of code (ie input entered is chris or sam). I don't understand why that is considering that all values are strings.
Here is my code:
name = input('What is your name?\n')
name = name.lower()
if name is 'chris':
print('Hi Chris!')
elif name is 'sam':
print('Hi Sam!')
else:
print('Who are you?')
Thanks in advance :)
You should be using == not is. Is tests whether one object is the same type as another (if value is None for e.g).

Categories

Resources