Click here to Skip to main content
15,435,837 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:
<
Quote:
We have the birthday date for:
Aya
Ayman
Rayan
Choose a person (don't worry about case sensitivity) : aya
Traceback (most recent call last):
File "Birthday.py", line 13, in <module>
show_date(birthday_dictionary)
File "Birthday.py", 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


Python
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():
                print(persons)
        person = input("Choose a person (don't worry about case sensitivity)")
        print(get_date(person,birthday_dictionary))
show_date(birthday_dictionary)


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.
Posted
Updated 26-Dec-20 2:48am
Comments
Richard MacCutchan 26-Dec-20 8:44am     CRLF
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
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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