Shubham Bhewanewala
Shubham Bhewanewala

Reputation: 597

Printing a tuple instead of text

x= input('What is your name? ')

print('Heloo',x)

The above code is giving an output ('Heloo', 5) for the input as 5. The above code is giving an output ('Heloo', 'shubham') for the input as 'shubham'. The above code is giving an error for the input as shubham without quotes.

Traceback (most recent call last):
  File "C:/Users/SHUBHAM/Desktop/Python1.py", line 1, in <module>
    x= input('What is your name? ')
  File "<string>", line 1, in <module>
NameError: name 'shubham' is not defined

Can anyone suggest me what is the error with my code? Thank You.

Upvotes: 0

Views: 30

Answers (1)

gold_cy
gold_cy

Reputation: 14236

shubham is not defined. It works for x because you are asking the user to define x, which is why when you call on it to print it works. It works in quotes because you are telling Python that it is a string but when you leave it without quotes it assumes it is a variable, but since you have not assigned anything to it, it gives you this error.

Upvotes: 2

Related Questions