+ 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.

25th Oct 2017, 10:28 AM
Oma Falk
Oma Falk - avatar
16 odpowiedzi
+ 6
My try- for i in (input(),[]):print (("Hello "+i) if (i in ("Alice","Bob")) else (""))
25th Oct 2017, 12:02 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 11
Shortest in Java?
25th Oct 2017, 12:13 PM
qwerty
qwerty - avatar
25th Oct 2017, 12:12 PM
qwerty
qwerty - avatar
25th Oct 2017, 11:17 PM
LukArToDo
LukArToDo - avatar
25th Oct 2017, 11:32 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 6
ok...@oma check my code now
25th Oct 2017, 4:55 PM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 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
25th Oct 2017, 2:01 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 4
https://code.sololearn.com/WkrpMwvBnDSz/?ref=app like this?
25th Oct 2017, 10:50 AM
Tio Misbaqul Irawan
Tio Misbaqul Irawan - avatar
+ 4
@Käzi yes simple in this version. But only output if name= Alice or Bob
25th Oct 2017, 11:38 AM
Oma Falk
Oma Falk - avatar
25th Oct 2017, 11:46 AM
Oma Falk
Oma Falk - avatar
+ 4
@110000 one statement less if possible
25th Oct 2017, 12:32 PM
Oma Falk
Oma Falk - avatar
+ 4
@swappi i dont understand your coding
25th Oct 2017, 12:38 PM
Oma Falk
Oma Falk - avatar
+ 4
@käzi not so bad....indeed really good! one point.. even not hallo if it is anna ot tom. but.. SOLVED cum laude
25th Oct 2017, 5:19 PM
Oma Falk
Oma Falk - avatar
+ 3
@swappi i still dont understand the convert for i in (a,[]).... means a will be appended to [] ?
25th Oct 2017, 4:09 PM
Oma Falk
Oma Falk - avatar
+ 1
not possible in CPP I think(in one line)
26th Oct 2017, 7:08 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
- 1
a whole new refreshing challenge## try it https://www.sololearn.com/discuss/817002/?ref=app
26th Oct 2017, 5:08 PM
sayan chandra
sayan chandra - avatar