[Tutor] Help with converting a string into a integer

Carmen Salcedo asc239 at live.com
Thu Oct 31 03:00:05 CET 2013


Hi Everyone,
I hope you're having a great week.  I'm working on this program that converts strings to integers. Can someone please help me out? :) Below is the program:
def main():    selection = input("Enter you choice. Enter 1 " +                   "for Phone Translator or 2 for Backward String.")    while selection != 1 and selection !=2:        print "Invalid choice"        selection = input("Please enter you selection. Enter 1 " +                   "for Phone Translator or 2 for Backward String.")    if selection == 1:        phoneTranslator()    elif selection == 2:        backwardString()
def phoneTranslator():    print "Phone Translator "    phoneNumber = raw_input ("Please enter the phone number: ")    phoneNumber = phoneNumber.upper()
    for n in phoneNumber:        if str.isalpha(n):            if n == "A" or n == "B" or n == "C":                n = "2"            elif n == "D" or n == "E" or n == "F":                n = "3"            elif n == "G" or n == "H" or n == "I":                n = "4"            elif n == "J" or n == "K" or n == "L":                n = 5            elif n == "M" or n == "N" or n == "O":                n = 6            elif n == "P" or n == "Q" or n == "R" or n == "S":                n = 7            elif n == "T" or n == "U" or n == "V":                n = "8"            else:                n = "9"
    print str.isalpha()                                 main()
Thanks!! :)
Carmen          		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131030/e0023c7a/attachment-0001.html>


More information about the Tutor mailing list