Python Translate Telephone Letter to Number Question











up vote
0
down vote

favorite












I know this has been asked before on this site, but I was unable to understand the answers given (I'm still very new), so I'm going to try and ask again. My assignment is to write code that takes a 10 digit phone number (XXX-XXX-XXXX) and converts any letters (i.e. 800-FLO-WERS) to numbers. I've wracked my brain on this, and could really use some help/explanations. In the class I'm taking (using the excellent "Starting out with Python, 4th edition, by Tony Gaddis), I cannot use concepts we have not covered (like dictionaries), but I can use lists/tuples. The code I've come up with follows:



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number
except Exception as err:
print(err)
def check_number(user_number):
try:
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number
except Exception as err:
print(err)
def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


Obviously, I'm not sure how to store the converted letter-to-number (considered doing it by indexing, but couldn't quite make that work either). I'm not looking for anyone to do my work for me, but a detailed explanation of what I'm doing wrong would be lovely.










share|improve this question






















  • your "for char in user_number:" loop never actually gets to run through its full duration, because your if/else conditions have a "return" keyword in it. the moment a return is encountered, the function stops and returns whatever it was instructed to return.
    – Paritosh Singh
    Nov 11 at 18:14















up vote
0
down vote

favorite












I know this has been asked before on this site, but I was unable to understand the answers given (I'm still very new), so I'm going to try and ask again. My assignment is to write code that takes a 10 digit phone number (XXX-XXX-XXXX) and converts any letters (i.e. 800-FLO-WERS) to numbers. I've wracked my brain on this, and could really use some help/explanations. In the class I'm taking (using the excellent "Starting out with Python, 4th edition, by Tony Gaddis), I cannot use concepts we have not covered (like dictionaries), but I can use lists/tuples. The code I've come up with follows:



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number
except Exception as err:
print(err)
def check_number(user_number):
try:
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number
except Exception as err:
print(err)
def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


Obviously, I'm not sure how to store the converted letter-to-number (considered doing it by indexing, but couldn't quite make that work either). I'm not looking for anyone to do my work for me, but a detailed explanation of what I'm doing wrong would be lovely.










share|improve this question






















  • your "for char in user_number:" loop never actually gets to run through its full duration, because your if/else conditions have a "return" keyword in it. the moment a return is encountered, the function stops and returns whatever it was instructed to return.
    – Paritosh Singh
    Nov 11 at 18:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I know this has been asked before on this site, but I was unable to understand the answers given (I'm still very new), so I'm going to try and ask again. My assignment is to write code that takes a 10 digit phone number (XXX-XXX-XXXX) and converts any letters (i.e. 800-FLO-WERS) to numbers. I've wracked my brain on this, and could really use some help/explanations. In the class I'm taking (using the excellent "Starting out with Python, 4th edition, by Tony Gaddis), I cannot use concepts we have not covered (like dictionaries), but I can use lists/tuples. The code I've come up with follows:



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number
except Exception as err:
print(err)
def check_number(user_number):
try:
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number
except Exception as err:
print(err)
def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


Obviously, I'm not sure how to store the converted letter-to-number (considered doing it by indexing, but couldn't quite make that work either). I'm not looking for anyone to do my work for me, but a detailed explanation of what I'm doing wrong would be lovely.










share|improve this question













I know this has been asked before on this site, but I was unable to understand the answers given (I'm still very new), so I'm going to try and ask again. My assignment is to write code that takes a 10 digit phone number (XXX-XXX-XXXX) and converts any letters (i.e. 800-FLO-WERS) to numbers. I've wracked my brain on this, and could really use some help/explanations. In the class I'm taking (using the excellent "Starting out with Python, 4th edition, by Tony Gaddis), I cannot use concepts we have not covered (like dictionaries), but I can use lists/tuples. The code I've come up with follows:



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number
except Exception as err:
print(err)
def check_number(user_number):
try:
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number
except Exception as err:
print(err)
def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


Obviously, I'm not sure how to store the converted letter-to-number (considered doing it by indexing, but couldn't quite make that work either). I'm not looking for anyone to do my work for me, but a detailed explanation of what I'm doing wrong would be lovely.







python python-3.x






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 18:01









deHart

358




358












  • your "for char in user_number:" loop never actually gets to run through its full duration, because your if/else conditions have a "return" keyword in it. the moment a return is encountered, the function stops and returns whatever it was instructed to return.
    – Paritosh Singh
    Nov 11 at 18:14


















  • your "for char in user_number:" loop never actually gets to run through its full duration, because your if/else conditions have a "return" keyword in it. the moment a return is encountered, the function stops and returns whatever it was instructed to return.
    – Paritosh Singh
    Nov 11 at 18:14
















your "for char in user_number:" loop never actually gets to run through its full duration, because your if/else conditions have a "return" keyword in it. the moment a return is encountered, the function stops and returns whatever it was instructed to return.
– Paritosh Singh
Nov 11 at 18:14




your "for char in user_number:" loop never actually gets to run through its full duration, because your if/else conditions have a "return" keyword in it. the moment a return is encountered, the function stops and returns whatever it was instructed to return.
– Paritosh Singh
Nov 11 at 18:14












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










The purpose of return is to return to the function where it was called. Here since return is inside the loop. It will exit the function in the first iteration.



for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number


Just use a list instead to store the converted values then return them after the loop using the join() method.



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number)
except Exception as err:
print(err)

def check_number(user_number):
try:
r =
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r.append(str(result))
else:
r.append(char)
return "".join(r)
except Exception as err:
print(err)

def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


If you can't use join()



def check_number(user_number):
try:
r = ''
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r += str(result)
else:
r += char
return r
except Exception as err:
print(err)





share|improve this answer























  • What's the " return "".join(r)" for?
    – deHart
    Nov 11 at 18:18










  • "separator".join(list) as the method name suggests joins strings inside a given list with separator. ":"join(['a','b','c']) gives a:b:c. If the separator is empty string then it just joins all the characters abc
    – Xnkr
    Nov 13 at 10:04




















up vote
0
down vote













This code:



if char.isalpha():
result = convert_to_num(char)
return result
else:
return char


Will return immediately with a single digit as the result. You want to return a string of all of the digits, not just the first digit, so you need to store the output digits and eventually return all of them (after the for loop is done) as a single string.



Initializing an empty list output = and appending the output digits to it after each iteration of the for loop, then returning the joined list (using "".join()) is a good way to accomplish this.



If you aren't allowed to use "".join(), you can also just build up a string (output = "" and output += char) and return it directly, but this will be slower.






share|improve this answer





















  • Where would the "output = """ and output += char go in the code, though? at the bottom of the check_numbers function? Or, the bottom of the convert_to_num function?
    – deHart
    Nov 11 at 18:35










  • You would initialize the empty output immediately before the for loop, and append to it inside the for loop (instead of using return). That way, you're starting with an empty string, and appending an output character to the string on each iteration of the loop; once the loop is done your string will contain all of the output characters.
    – Ollin Boer Bohan
    Nov 11 at 18:37










  • I think I understand what you're saying, but is there any way you could type it out for me so I can see how the output works with the entire code. I apologize, everyone who's posted on my question has helped me a LOT, I'm just having trouble tweaking the code using the output = '', output += char (I know what they mean/do, but I'm unsure how to utilize them in this context).
    – deHart
    Nov 11 at 18:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251611%2fpython-translate-telephone-letter-to-number-question%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










The purpose of return is to return to the function where it was called. Here since return is inside the loop. It will exit the function in the first iteration.



for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number


Just use a list instead to store the converted values then return them after the loop using the join() method.



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number)
except Exception as err:
print(err)

def check_number(user_number):
try:
r =
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r.append(str(result))
else:
r.append(char)
return "".join(r)
except Exception as err:
print(err)

def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


If you can't use join()



def check_number(user_number):
try:
r = ''
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r += str(result)
else:
r += char
return r
except Exception as err:
print(err)





share|improve this answer























  • What's the " return "".join(r)" for?
    – deHart
    Nov 11 at 18:18










  • "separator".join(list) as the method name suggests joins strings inside a given list with separator. ":"join(['a','b','c']) gives a:b:c. If the separator is empty string then it just joins all the characters abc
    – Xnkr
    Nov 13 at 10:04

















up vote
0
down vote



accepted










The purpose of return is to return to the function where it was called. Here since return is inside the loop. It will exit the function in the first iteration.



for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number


Just use a list instead to store the converted values then return them after the loop using the join() method.



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number)
except Exception as err:
print(err)

def check_number(user_number):
try:
r =
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r.append(str(result))
else:
r.append(char)
return "".join(r)
except Exception as err:
print(err)

def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


If you can't use join()



def check_number(user_number):
try:
r = ''
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r += str(result)
else:
r += char
return r
except Exception as err:
print(err)





share|improve this answer























  • What's the " return "".join(r)" for?
    – deHart
    Nov 11 at 18:18










  • "separator".join(list) as the method name suggests joins strings inside a given list with separator. ":"join(['a','b','c']) gives a:b:c. If the separator is empty string then it just joins all the characters abc
    – Xnkr
    Nov 13 at 10:04















up vote
0
down vote



accepted







up vote
0
down vote



accepted






The purpose of return is to return to the function where it was called. Here since return is inside the loop. It will exit the function in the first iteration.



for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number


Just use a list instead to store the converted values then return them after the loop using the join() method.



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number)
except Exception as err:
print(err)

def check_number(user_number):
try:
r =
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r.append(str(result))
else:
r.append(char)
return "".join(r)
except Exception as err:
print(err)

def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


If you can't use join()



def check_number(user_number):
try:
r = ''
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r += str(result)
else:
r += char
return r
except Exception as err:
print(err)





share|improve this answer














The purpose of return is to return to the function where it was called. Here since return is inside the loop. It will exit the function in the first iteration.



for char in user_number:
if char.isalpha():
result = convert_to_num(char)
return result
else:
return char
return converted_number


Just use a list instead to store the converted values then return them after the loop using the join() method.



def main():
try:
user_number = str(input('Enter a phone number (XXX-XXX-XXXX): ')).upper()
converted_number = check_number(user_number)
print('The phone number is:',converted_number)
except Exception as err:
print(err)

def check_number(user_number):
try:
r =
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r.append(str(result))
else:
r.append(char)
return "".join(r)
except Exception as err:
print(err)

def convert_to_num(char):
if char in ['A','B','C']:
char = 2
elif char in ['D','E','F']:
char = 3
elif char in ['G','H','I']:
char = 4
elif char in ['J','K','L']:
char = 5
elif char in ['M','N','O']:
char = 6
elif char in ['P','Q','R','S']:
char = 7
elif char in ['T','U','V']:
char = 8
elif char in ['W','X','Y','Z']:
char = 9
return char
main()


If you can't use join()



def check_number(user_number):
try:
r = ''
for char in user_number:
if char.isalpha():
result = convert_to_num(char)
r += str(result)
else:
r += char
return r
except Exception as err:
print(err)






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 at 10:07

























answered Nov 11 at 18:10









Xnkr

405313




405313












  • What's the " return "".join(r)" for?
    – deHart
    Nov 11 at 18:18










  • "separator".join(list) as the method name suggests joins strings inside a given list with separator. ":"join(['a','b','c']) gives a:b:c. If the separator is empty string then it just joins all the characters abc
    – Xnkr
    Nov 13 at 10:04




















  • What's the " return "".join(r)" for?
    – deHart
    Nov 11 at 18:18










  • "separator".join(list) as the method name suggests joins strings inside a given list with separator. ":"join(['a','b','c']) gives a:b:c. If the separator is empty string then it just joins all the characters abc
    – Xnkr
    Nov 13 at 10:04


















What's the " return "".join(r)" for?
– deHart
Nov 11 at 18:18




What's the " return "".join(r)" for?
– deHart
Nov 11 at 18:18












"separator".join(list) as the method name suggests joins strings inside a given list with separator. ":"join(['a','b','c']) gives a:b:c. If the separator is empty string then it just joins all the characters abc
– Xnkr
Nov 13 at 10:04






"separator".join(list) as the method name suggests joins strings inside a given list with separator. ":"join(['a','b','c']) gives a:b:c. If the separator is empty string then it just joins all the characters abc
– Xnkr
Nov 13 at 10:04














up vote
0
down vote













This code:



if char.isalpha():
result = convert_to_num(char)
return result
else:
return char


Will return immediately with a single digit as the result. You want to return a string of all of the digits, not just the first digit, so you need to store the output digits and eventually return all of them (after the for loop is done) as a single string.



Initializing an empty list output = and appending the output digits to it after each iteration of the for loop, then returning the joined list (using "".join()) is a good way to accomplish this.



If you aren't allowed to use "".join(), you can also just build up a string (output = "" and output += char) and return it directly, but this will be slower.






share|improve this answer





















  • Where would the "output = """ and output += char go in the code, though? at the bottom of the check_numbers function? Or, the bottom of the convert_to_num function?
    – deHart
    Nov 11 at 18:35










  • You would initialize the empty output immediately before the for loop, and append to it inside the for loop (instead of using return). That way, you're starting with an empty string, and appending an output character to the string on each iteration of the loop; once the loop is done your string will contain all of the output characters.
    – Ollin Boer Bohan
    Nov 11 at 18:37










  • I think I understand what you're saying, but is there any way you could type it out for me so I can see how the output works with the entire code. I apologize, everyone who's posted on my question has helped me a LOT, I'm just having trouble tweaking the code using the output = '', output += char (I know what they mean/do, but I'm unsure how to utilize them in this context).
    – deHart
    Nov 11 at 18:50















up vote
0
down vote













This code:



if char.isalpha():
result = convert_to_num(char)
return result
else:
return char


Will return immediately with a single digit as the result. You want to return a string of all of the digits, not just the first digit, so you need to store the output digits and eventually return all of them (after the for loop is done) as a single string.



Initializing an empty list output = and appending the output digits to it after each iteration of the for loop, then returning the joined list (using "".join()) is a good way to accomplish this.



If you aren't allowed to use "".join(), you can also just build up a string (output = "" and output += char) and return it directly, but this will be slower.






share|improve this answer





















  • Where would the "output = """ and output += char go in the code, though? at the bottom of the check_numbers function? Or, the bottom of the convert_to_num function?
    – deHart
    Nov 11 at 18:35










  • You would initialize the empty output immediately before the for loop, and append to it inside the for loop (instead of using return). That way, you're starting with an empty string, and appending an output character to the string on each iteration of the loop; once the loop is done your string will contain all of the output characters.
    – Ollin Boer Bohan
    Nov 11 at 18:37










  • I think I understand what you're saying, but is there any way you could type it out for me so I can see how the output works with the entire code. I apologize, everyone who's posted on my question has helped me a LOT, I'm just having trouble tweaking the code using the output = '', output += char (I know what they mean/do, but I'm unsure how to utilize them in this context).
    – deHart
    Nov 11 at 18:50













up vote
0
down vote










up vote
0
down vote









This code:



if char.isalpha():
result = convert_to_num(char)
return result
else:
return char


Will return immediately with a single digit as the result. You want to return a string of all of the digits, not just the first digit, so you need to store the output digits and eventually return all of them (after the for loop is done) as a single string.



Initializing an empty list output = and appending the output digits to it after each iteration of the for loop, then returning the joined list (using "".join()) is a good way to accomplish this.



If you aren't allowed to use "".join(), you can also just build up a string (output = "" and output += char) and return it directly, but this will be slower.






share|improve this answer












This code:



if char.isalpha():
result = convert_to_num(char)
return result
else:
return char


Will return immediately with a single digit as the result. You want to return a string of all of the digits, not just the first digit, so you need to store the output digits and eventually return all of them (after the for loop is done) as a single string.



Initializing an empty list output = and appending the output digits to it after each iteration of the for loop, then returning the joined list (using "".join()) is a good way to accomplish this.



If you aren't allowed to use "".join(), you can also just build up a string (output = "" and output += char) and return it directly, but this will be slower.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 18:16









Ollin Boer Bohan

1,365310




1,365310












  • Where would the "output = """ and output += char go in the code, though? at the bottom of the check_numbers function? Or, the bottom of the convert_to_num function?
    – deHart
    Nov 11 at 18:35










  • You would initialize the empty output immediately before the for loop, and append to it inside the for loop (instead of using return). That way, you're starting with an empty string, and appending an output character to the string on each iteration of the loop; once the loop is done your string will contain all of the output characters.
    – Ollin Boer Bohan
    Nov 11 at 18:37










  • I think I understand what you're saying, but is there any way you could type it out for me so I can see how the output works with the entire code. I apologize, everyone who's posted on my question has helped me a LOT, I'm just having trouble tweaking the code using the output = '', output += char (I know what they mean/do, but I'm unsure how to utilize them in this context).
    – deHart
    Nov 11 at 18:50


















  • Where would the "output = """ and output += char go in the code, though? at the bottom of the check_numbers function? Or, the bottom of the convert_to_num function?
    – deHart
    Nov 11 at 18:35










  • You would initialize the empty output immediately before the for loop, and append to it inside the for loop (instead of using return). That way, you're starting with an empty string, and appending an output character to the string on each iteration of the loop; once the loop is done your string will contain all of the output characters.
    – Ollin Boer Bohan
    Nov 11 at 18:37










  • I think I understand what you're saying, but is there any way you could type it out for me so I can see how the output works with the entire code. I apologize, everyone who's posted on my question has helped me a LOT, I'm just having trouble tweaking the code using the output = '', output += char (I know what they mean/do, but I'm unsure how to utilize them in this context).
    – deHart
    Nov 11 at 18:50
















Where would the "output = """ and output += char go in the code, though? at the bottom of the check_numbers function? Or, the bottom of the convert_to_num function?
– deHart
Nov 11 at 18:35




Where would the "output = """ and output += char go in the code, though? at the bottom of the check_numbers function? Or, the bottom of the convert_to_num function?
– deHart
Nov 11 at 18:35












You would initialize the empty output immediately before the for loop, and append to it inside the for loop (instead of using return). That way, you're starting with an empty string, and appending an output character to the string on each iteration of the loop; once the loop is done your string will contain all of the output characters.
– Ollin Boer Bohan
Nov 11 at 18:37




You would initialize the empty output immediately before the for loop, and append to it inside the for loop (instead of using return). That way, you're starting with an empty string, and appending an output character to the string on each iteration of the loop; once the loop is done your string will contain all of the output characters.
– Ollin Boer Bohan
Nov 11 at 18:37












I think I understand what you're saying, but is there any way you could type it out for me so I can see how the output works with the entire code. I apologize, everyone who's posted on my question has helped me a LOT, I'm just having trouble tweaking the code using the output = '', output += char (I know what they mean/do, but I'm unsure how to utilize them in this context).
– deHart
Nov 11 at 18:50




I think I understand what you're saying, but is there any way you could type it out for me so I can see how the output works with the entire code. I apologize, everyone who's posted on my question has helped me a LOT, I'm just having trouble tweaking the code using the output = '', output += char (I know what they mean/do, but I'm unsure how to utilize them in this context).
– deHart
Nov 11 at 18:50


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251611%2fpython-translate-telephone-letter-to-number-question%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."