#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0

    Python Result to Number


    Hi

    Can I get some assistance with the following

    Code:

    Letter = raw_input("Enter Letter")
    A = 7
    B = 8
    C = 9
    print Letter

    I have left the basic info but if the Letter A is entered in the print Letter it results A, I want it to give the result 7

    Jezza
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    149
    Rep Power
    140
    Hi,


    I'm not sure whether I understood your problem exactly, but what I understand is that you wish to map each letter into the numeric values defined for those corresponding letters in your code. For me that works like a dictionary

    Code:
    >>> dictionary = {'A':7, 'B':8, 'C':9}
    >>> letter = raw_input('Enter letter: ')
    Enter letter: A
    >>>
    >>> print (dictionary[letter])
    7
    >>>

    Regards,
    Dariyoosh
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0
    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo