[Tutor] Help with converting a string into a integer

bob gailer bgailer at gmail.com
Thu Oct 31 11:34:04 CET 2013


On 10/30/2013 10:00 PM, Carmen Salcedo wrote:

 > Hi Everyone,

hi

some guidelines for this list.
   post in plain text not html.
   tell us what version of Python you are using, what OS, what you use 
to edit and run the program.
   when replying:
     reply-all so a copy goes to the list
     put your responses following the relevant text
     delete irrelevant text
     if you get an exception (error) post the entire traceback. example:

File "N:\foo.py", line 2, in <module>
     2/0
ZeroDivisionError: division by zero

 > 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? :)

What kind of help do you want?
It is a lot easier for us and more profitable for you when you
   are specific
   tell us what kind of help you need
   did you run the program?
   what did you get and what did you expect?

 >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

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list