Click here to Skip to main content
15,945,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know there are differences between python 2 and python 3 and I feel like this is a good occasion to learn about some of them.
I get this error when executing python2:
We have the birthday date for:
Choose a person (don't worry about case sensitivity) : aya
Traceback (most recent call last):
File "", line 13, in <module>
File "", line 11, in show_date
person = input("Choose a person (don't worry about case sensitivity) : ")
File "<string>", line 1, in <module>
NameError: name 'aya' is not defined

birthday_dictionary = {"Rayan":"24/10/2008","Aya":"12/9/2004","Ayman":"31/10/20"}
def get_date(person,birthday_dictionary):
        person = person.lower()
        for someone in birthday_dictionary.keys():
                if person == someone.lower():
                        return birthday_dictionary[someone]
def show_date(birthday_dictionary):
        print(" We have the birthday date for: ")
        for persons in birthday_dictionary.keys():
        person = input("Choose a person (don't worry about case sensitivity)")

What I have tried:

I am clueless given the fact I have never encountered such a problem, thank you for any help you may provide.
Updated 26-Dec-20 2:48am
Richard MacCutchan 26-Dec-20 8:44am    
That should also work in Python 2. Are you sure it is the exact same code?
As stated by OriginalGriff.

1 solution

The difference is that input changed between the two versions (the later version is much more sensible): Python Tutorial: Keyboard Input[^] (look at the last section "Differences between Python2 and Python3")
Change input to raw_input and it'll work in Python2 (but not in Python 3 where input is correct!)
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900