![]() |
|
[Python] Need help (easy python task) - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Need help (easy python task) (/showthread.php?tid=5177751) |
Need help (easy python task) - Gameh3x - Feb 20, 2016 Hey, I really need some help. Can someone send me a code that asks the user for his/her name and prints out each letter of the name separately? It's for my python class, I was sick for like 2 weeks straight and now I can't do shit 🤝 * - Stealth™ - Feb 20, 2016 "prints out each letter of the name separately?" What do you mean by this? And I offer Java/Python services, feel free to contact me on Skype @ Eclips3.HF * - Gameh3x - Feb 20, 2016 (Feb 20, 2016 12:37 PM)Stealth™ Wrote: "prints out each letter of the name separately?" I'm not sure but lets say it asks for your name, you type in "Tom" and it prints T, O, M like this but with using a cycle and not typing out "print" all the time. I'm bad at english, i dont know if you got me 😵
* - Retribute - Feb 20, 2016 I'm not on my computer right now, but you'll need a loop like this. PHP Code * - Stealth™ - Feb 20, 2016 (Feb 20, 2016 12:45 PM)Gameh3x Wrote: I'm not sure but lets say it asks for your name, you type in "Tom" and it prints T, O, M like this I'm guessing you mean that it prints each letter on a new line? You can just tack on '\n' after each letter when printing in a for-loop. * - SIM-1866423 - Feb 20, 2016 PHP Code ?? .. * - Sophocles - Feb 20, 2016 Code name = str(input("Name :"))Can also be done in 2 lines but who cares... This is 100% what you need, easiest and cleanest way of doing it. * - Goodies - Feb 20, 2016 (Feb 20, 2016 01:57 PM)b3mb4m Wrote: haha not really. That's just going to print out a list. The easiest you can do is: PHP Code That'll at least work in python 2/3 (Feb 20, 2016 12:50 PM)Retribute Wrote: I'm not on my computer right now, but you'll need a loop like this. Why have a counter? Even if you wanted to use a loop, you can just do: PHP Code * - Feanor - Feb 20, 2016 For the sake of 2 lines of code you may as well just tried to do it yourself, anyone that gave you the answer in this thread didn't actually help you. * - ʆɛѳɗɑʀkZ - Feb 27, 2016 I can help you with this, I am a Computer Engineering student.. Just PM me if you want... * - EwilDave - Feb 27, 2016 For completion's sake, there's a one-line way of writing this: Code [print(letter) for letter in input("Username: ")]A breakdown of what the code is doing: This process is called list comprehension as we iterate through a list(Your username is a list of characters/letters) - each of these is printed one after another. * - Akhilesh v sali - Feb 27, 2016 Still searching for code pm me |