python variable is not defined using print function

4361 views python
-1

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?

answered question

When I run this code, I get It is definitely nice to meet you tony !

1 Answer

12

You need to use "+" Instead of commas since you're adding the input. like so:

print('It is definitely nice to meet you '+nm+'!')

posted this

Have an answer?

JD

Please login first before posting an answer.