Feb 20, 2016 12:36 PM
(This post was last modified: Feb 20, 2016 12:37 PM by Gameh3x.)
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 🤝
DO NOT DEAL WITH THIS MEMBER
"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
(Feb 20, 2016 12:37 PM)Stealth™ Wrote: "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
I'm not sure but lets say it asks for your name, you type in "Tom" and it prints T, O, M like this ![[Image: Nb9KrY5.png]](https://i.imgur.com/Nb9KrY5.png) 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 😵
Feb 20, 2016 12:50 PM
(This post was last modified: Feb 20, 2016 12:50 PM by Retribute.)
I'm not on my computer right now, but you'll need a loop like this.
PHP Code
<?php i=0 while i < len(text): print text[i] i += 1
DO NOT DEAL WITH THIS MEMBER
(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 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 😵
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.
DO NOT DEAL WITH THIS MEMBER
PHP Code
<?php print [x for x in "b3mb4m"]
?? ..
DO NOT DEAL WITH THIS MEMBER
Feb 20, 2016 02:12 PM
(This post was last modified: Feb 20, 2016 02:14 PM by Sophocles.)
Code name = str(input("Name :"))
for elt in name :
print(elt)
Can also be done in 2 lines but who cares...
This is 100% what you need, easiest and cleanest way of doing it.
Feb 20, 2016 04:32 PM
(This post was last modified: Feb 20, 2016 04:33 PM by Goodies.)
(Feb 20, 2016 01:57 PM)SIM-1866423 Wrote: PHP Code
<?php print [x for x in "b3mb4m"]
?? ..
haha not really. That's just going to print out a list. The easiest you can do is:
PHP Code
<?php print('\n'.join(list("YourNamehere")))
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.
PHP Code
<?php i=0 while i < len(text): print text[i] i += 1
Why have a counter? Even if you wanted to use a loop, you can just do:
PHP Code
<?php for letter in "YourNameHere": print(letter)
DO NOT DEAL WITH THIS MEMBER
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.
I can help you with this, I am a Computer Engineering student.. Just PM me if you want...
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.
Still searching for code pm me
|