-
Code def Complicated_Greetings(name): # using the orignial logic to make it more readable. h=["H","e","l","l","o"] c="," w=["W","o","r","l","d"] e="!" k="" # build each term hello= ''.join(h) #create string from list comma= ' ' if name else c+ ' ' #whitespace, or comma plus whitespace world= ''.join(w) if not name else "" #create string from list or nothing name= name if name else '' #name or nothing exclamation= e* 2 if not name else "" #two exclamations or nothing return hello+ comma+ world+ name+ exclamation #build the final string and return it
Test Cases import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) .describe("Brand New Triple A RPG Game") def test_group(): .it("Check with name") def test_case(): test.assert_equals(Complicated_Greetings("Femi"), "Hello Femi") .it("Check without name") def test_case(): test.assert_equals(Complicated_Greetings(""), "Hello, World!!")
Output:
-
Code - def Complicated_Greetings(name):
- # using the orignial logic to make it more readable.
- h=["H","e","l","l","o"]
- c=","
- w=["W","o","r","l","d"]
- e="!"
- k=""
for i in h:k+=iif name=="":k+=ck+=" "for i in w:k+=ik=k+e+eelse:k+=" "k+=namereturn k- # build each term
- hello= ''.join(h) #create string from list
- comma= ' ' if name else c+ ' ' #whitespace, or comma plus whitespace
- world= ''.join(w) if not name else "" #create string from list or nothing
- name= name if name else '' #name or nothing
- exclamation= e* 2 if not name else "" #two exclamations or nothing
- return hello+ comma+ world+ name+ exclamation #build the final string and return it
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}