Python Challenges: Phone number problem


English (Auto-generated)

today. We're gonna we're back with another python challenge where basically what we're going to be doing is we're going to be given a list with 10 numbers always and we're gonna turn that into a phone number. Um So the former we're gonna use is inside a current decision have the first three numbers on the list, then another set of three numbers a dash and then four numbers like so Okay. So I hope that you guys understand that and we're gonna go ahead and do a small for me to turn that list into the string. It's not the order the usual way to turn it into a string. But we're just gonna do it this way because I can get more interesting. Okay. So we're going for the four number or numb in list six. We're gonna make the list. Thanks equal to the string version of No. Alright, perfect. And we're gonna plus Equals 1 2 Index. So indifferently changes. And now what we're gonna do is actually do the format of the phone number. Now, that's all that the list is it's true. Okay. Okay. So what we're gonna do here is phone book called phone number. We're gonna make it equal to brackets there and we're gonna have the first premises and then we're going to use something slaves notation where basically put list and we want everything up to the third Up to the 3rd Number. Well including the third number actually. And then we're gonna ride it in a little risk with outside parentheses. The ending parentheses. I mean like um And then we're gonna add a space right there. But that's how that has to be inside of. Okay then we're going to do we won't open the back we want we're going to start doing this operation now until after the third um number. And we're gonna do it up to The 6th # six No. Close and then we're gonna have so that's a dash and plus and then we're going to do one last sides sides education and we do every number after the sixth number. And since we know it's going to contain 10 numbers and we know that's just gonna be four numbers right? Therefore in two years four elements. Okay. Um and that we could put here up to the 10th number but like I said we know that it's only the numbers then it's fine as it is. Okay. Actually here we put list and here we need once again. Okay perfect. Now we're just going to make that into but stream back into the stream. Okay? And we're gonna join it by nothing. String dot join. And what do we want to join? We want to join. Fun number list. That is what we want to join. And then we just return phone number. Oh string. Okay. Mr Okay. And now let's try it out. Let's have a let's see. Okay print we're gonna print some number And we're gonna make full list equal to (123) 456 7 eight 9, 10 0 10 numbers right there. Okay, let's open up our terminal right here. And let's just put python soon. Three faith and then the name of our file like always. And it returns it in number four as you can see right there. Okay, now let's try it with a few different numbers, although it should work. Let's try this but backwards 09 okay. Like 2346 6678 and one. Okay, let's see this turned out now. Okay. Okay. And they returned to the phone number four with 234 inside the parentheses 666 dash 78 91. Perfect. And as you can see it works perfectly if you guys have any out of many different ways to factor this or clean up the code a little bit or you just came up with a completely different solution in general, then let me know if you can check it out. Thank you so much for watching this yeah, Podcast and see you on the next one. Good bye.
9 Views 0 Likes 0 Comments

We are given a list with 10 numbers in it, our job is to be given those ten numbers and turn them into a phone number in the following format: (123) 456-7890 Good luck to us!

Leave a comment (supports markdown format)