+ 5
[ Challenge ] greeting in one line of code
ask for a name and print hello [name] if and only if name is Alice or Bob. only one line of code allowed.
16 Réponses
+ 6
My try-
for i in (input(),[]):print (("Hello "+i) if (i in ("Alice","Bob")) else (""))
+ 11
Shortest in Java?
+ 10
Here's my try :
https://code.sololearn.com/cJQTqWQpd2ax/?ref=app
+ 8
+ 6
ok...@oma check my code now
+ 5
Well, let me try to explain my code. I convert the input into an array (not a char array but a string array) with only one element that is, the input. Then, it will print it if it is "Alice" or "Bob" else it will print nothing.
I added the code so that you can run it directly.
https://code.sololearn.com/cbMmze8lYoG4/?ref=app
+ 4
https://code.sololearn.com/WkrpMwvBnDSz/?ref=app like this?
+ 4
@Käzi yes simple in this version. But only output if name= Alice or Bob
+ 4
+ 4
@110000 one statement less if possible
+ 4
@swappi i dont understand your coding
+ 4
@käzi not so bad....indeed really good!
one point..
even not hallo if it is anna ot tom.
but.. SOLVED cum laude
+ 3
@swappi i still dont understand the convert
for i in (a,[])....
means a will be appended to [] ?
+ 1
not possible in CPP I think(in one line)
- 1
a whole new refreshing challenge##
try it
https://www.sololearn.com/discuss/817002/?ref=app