[Tutor] Help with converting a string into a integer

Carmen Salcedo asc239 at live.com
Thu Oct 31 15:11:40 CET 2013


Thanks Bob! :) A list is great idea. I'm just trying to figure out how to print the number across like a phone number 555-5555 instead of downward. I'm stuck on that.

5
5
5

Thanks again!

Carmen
Sent from my iPhone

On Oct 31, 2013, at 9:02 AM, "bob gailer" <bgailer at gmail.com> wrote:

> On 10/31/2013 7:52 AM, Carmen Salcedo wrote:
>> I'm not able to post it right now. All I did to the previous program i emailed was changed isalpha() to str.isalpha.
> That does agree with what you posted or got.
> 
> The part of your original program that should print a character already is 
>     print (str.isalpha()
> which raises this exception:
> 
>   File "N:\Script2.py", line 37, in phoneTranslator
>     print(str.isalpha())
> TypeError: descriptor 'isalpha' of 'str' object needs an argument
> 
> it should be
> 
> print n
> 
> Exactly what did you type in response to 
>     phoneNumber = raw_input ("Please enter the phone number: ")
> 
> Note you are not consistent in converting letters:
>             elif n == "G" or n == "H" or n == "I":
>                 n = "4"
>             elif n == "J" or n == "K" or n == "L":
>                 n = 5
> all the numbers should be characters e.g. 
>                 n = "5"
> etc.
> 
> There are many ways to get the desired output.
> One is:
>   collect the characters in one list, say numberList
>   Then use slicing to insert the "-" e.g. numberList[3:3] = "-"
>   Then print "".join(numberList)
> 
> -- 
> Bob Gailer
> 919-636-4239
> Chapel Hill NC


More information about the Tutor mailing list