I am new to python and I am trying to learn the language while also trying to see some differences between python2.7 & python 3.
I understand the fundamental difference between python2.7 and python3 with respect to input from resources like this
Here is what I am trying to do:
relation = {"saurav": { "age":21, "profession" : "student"}, "rini": {"age": 28, "profession" :"singer"}}
print(relation["rini"])
print("___________________")
print(relation["saurav"])
print("**************")
name = str(input("Enter name "))
print(name)
print(relation[name])
and when I run the above code in python3 I get the expected response. But when I run the same code in python 2.7, I get an error as below:
Traceback (most recent call last):
File "rish.py", line 6, in <module>
name = str(input("Enter name "))
File "<string>", line 1, in <module>
NameError: name 'rini' is not defined
This is how my output looks like:
Can someone please help me understand why am I getting this error in python2.7 and not in python 3?