changes
- Internet username checker
- Using custom check function
- Cool -> Kool
- Testcases have been brought back.
- Removed comment about having lots of edge cases.
I really hope these improvements will help the development of the you_are_cool/you_are_kool/youAreCool/youAreKool(coming soon) programs in the future. Thanks for everyone who has supported the development of this program. Thanks a lot.
# if and then a series of elif's is FASTER. def you_are_kool(n): if not isinstance(n, str): return "Wait, so your name ISN'T a string of text?! That's wild!" n = n.strip() if not n: return "There is no name, so I'm not complimenting you. LOL..." elif len(n) > 100: return "Man, you have an insanely long name! Do people call you by your full name or just a nickname?" elif n.isdigit(): return "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!" elif any(char in n for char in "!@#$%^&*()_+=[]\\/<>,.`~"): return f"Hello {n}, you are very kool! But is that your internet name?!" return f"Hello {n}, you are very kool!"
def you_are_cool(n="Taki"):- # if and then a series of elif's is FASTER.
- def you_are_kool(n):
- if not isinstance(n, str):
- return "Wait, so your name ISN'T a string of text?! That's wild!"
- n = n.strip()
- if not n:
return "There is no name, so I'm not complimenting you. LOL"if len(n) > 100:- return "There is no name, so I'm not complimenting you. LOL..."
- elif len(n) > 100:
- return "Man, you have an insanely long name! Do people call you by your full name or just a nickname?"
if n.isdigit():- elif n.isdigit():
- return "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!"
return f"Hello {n}, you are very cool!"# edge case go BRRR- elif any(char in n for char in "!@#$%^&*()_+=[]\\/<>,.`~"):
- return f"Hello {n}, you are very kool! But is that your internet name?!"
- return f"Hello {n}, you are very kool!"
# I've preloaded the check function so yeah check(you_are_kool('tetra-coder'), 'Hello tetra-coder, you are very kool!') check(you_are_kool("123!@#"), 'Hello 123!@#, you are very kool! But is that your internet name?!') check(you_are_kool("kool"), 'Hello kool, you are very kool!') # cursed check(you_are_kool(""), "There is no name, so I'm not complimenting you. LOL...") check(you_are_kool(123), "Wait, so your name ISN'T a string of text?! That's wild!") check(you_are_kool("a" * 101), "Man, you have an insanely long name! Do people call you by your full name or just a nickname?") check(you_are_kool("42"), "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!") check(you_are_kool("John Doe"), "Hello John Doe, you are very kool!")
import codewars_test as testfrom solution import you_are_cool- # I've preloaded the check function so yeah
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(you_are_cool('tetra-coder'), 'Hello tetra-coder, you are very cool!')test.assert_equals(you_are_cool("123!@#"), 'Hello 123!@#, you are very cool!')test.assert_equals(you_are_cool("cool"), 'Hello cool, you are very cool!') #cursedtest.assert_equals(you_are_cool(""), "There is no name, so I'm not complimenting you. LOL")test.assert_equals(you_are_cool(123), "Wait, so your name ISN'T a string of text?! That's wild!")test.assert_equals(you_are_cool("a" * 101), "Man, you have an insanely long name! Do people call you by your full name or just a nickname?")test.assert_equals(you_are_cool("42"), "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!")test.assert_equals(you_are_cool("John Doe"), "Hello John Doe, you are very cool!")# edge case testing go BRRRR- check(you_are_kool('tetra-coder'), 'Hello tetra-coder, you are very kool!')
- check(you_are_kool("123!@#"), 'Hello 123!@#, you are very kool! But is that your internet name?!')
- check(you_are_kool("kool"), 'Hello kool, you are very kool!') # cursed
- check(you_are_kool(""), "There is no name, so I'm not complimenting you. LOL...")
- check(you_are_kool(123), "Wait, so your name ISN'T a string of text?! That's wild!")
- check(you_are_kool("a" * 101), "Man, you have an insanely long name! Do people call you by your full name or just a nickname?")
- check(you_are_kool("42"), "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!")
- check(you_are_kool("John Doe"), "Hello John Doe, you are very kool!")
more tests and more edge case testing lol
def you_are_cool(n): if not isinstance(n, str): return "Wait, so your name ISN'T a string of text?! That's wild!" elif n.strip() == "": return "There is no name, so I'm not complimenting you. LOL" elif len(n.strip()) > 100: return "Man, you have an insanely long name! Do people call you by your full name or just a nickname?" elif n.strip().isdigit(): return "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!" else: return "Hello " + n.strip() + ", you are very cool!" # edge case go BRRR
def your_name(n="Taki"):return f"Hello {n}, you are very kool!"- def you_are_cool(n):
- if not isinstance(n, str):
- return "Wait, so your name ISN'T a string of text?! That's wild!"
- elif n.strip() == "":
- return "There is no name, so I'm not complimenting you. LOL"
- elif len(n.strip()) > 100:
- return "Man, you have an insanely long name! Do people call you by your full name or just a nickname?"
- elif n.strip().isdigit():
- return "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!"
- else:
- return "Hello " + n.strip() + ", you are very cool!"
- # edge case go BRRR
import codewars_test as test from solution import you_are_cool # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(you_are_cool('tetra-coder'), 'Hello tetra-coder, you are very cool!') test.assert_equals(you_are_cool("123!@#"), 'Hello 123!@#, you are very cool!') test.assert_equals(you_are_cool("cool"), 'Hello cool, you are very cool!') #cursed test.assert_equals(you_are_cool(""), "There is no name, so I'm not complimenting you. LOL") test.assert_equals(you_are_cool(123), "Wait, so your name ISN'T a string of text?! That's wild!") test.assert_equals(you_are_cool("a" * 101), "Man, you have an insanely long name! Do people call you by your full name or just a nickname?") test.assert_equals(you_are_cool("42"), "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!") test.assert_equals(you_are_cool("John Doe"), "Hello John Doe, you are very cool!") # edge case testing go BRRRR
- import codewars_test as test
from solution import your_name- from solution import you_are_cool
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(your_name(), 'Hello Taki, you are very kool!')test.assert_equals(your_name("Lorelai"), 'Hello Lorelai, you are very kool!')test.assert_equals(your_name("Rocky"), 'Hello Rocky, you are very kool!')- test.assert_equals(you_are_cool('tetra-coder'), 'Hello tetra-coder, you are very cool!')
- test.assert_equals(you_are_cool("123!@#"), 'Hello 123!@#, you are very cool!')
- test.assert_equals(you_are_cool("cool"), 'Hello cool, you are very cool!') #cursed
- test.assert_equals(you_are_cool(""), "There is no name, so I'm not complimenting you. LOL")
- test.assert_equals(you_are_cool(123), "Wait, so your name ISN'T a string of text?! That's wild!")
- test.assert_equals(you_are_cool("a" * 101), "Man, you have an insanely long name! Do people call you by your full name or just a nickname?")
- test.assert_equals(you_are_cool("42"), "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!")
- test.assert_equals(you_are_cool("John Doe"), "Hello John Doe, you are very cool!")
- # edge case testing go BRRRR
This code now shows how reversing a string works. Reversing a string is just changing the order in which a string is read. New test cases have been added too. If you really wanted the shortest code possible, I am very sorry to upset you. But I can change it if you want to.
def flip_str(string): idx = -1 # Start index for reversing new_string = "" # Create an empty string to store the reversed string for val in string: new_string += string[idx] # Add characters from the original string in reverse order idx -= 1 # Move to the previous character in the original string return new_string
reverse_string = lambda string: "".join(reversed(string))- def flip_str(string):
- idx = -1 # Start index for reversing
- new_string = "" # Create an empty string to store the reversed string
- for val in string:
- new_string += string[idx] # Add characters from the original string in reverse order
- idx -= 1 # Move to the previous character in the original string
- return new_string
import codewars_test as test from solution import flip_str @test.describe("Testing") def a(): @test.it("String Reversal Tests") def a(): test.assert_equals(flip_str(''), '') test.assert_equals(flip_str('a'), 'a') test.assert_equals(flip_str('hello'), 'olleh') test.assert_equals(flip_str('world'), 'dlrow') test.assert_equals(flip_str('hello world'), 'dlrow olleh') test.assert_equals(flip_str('abc123!@#'), '#@!321cba') test.assert_equals(flip_str('HelloWorld'), 'dlroWolleH') test.assert_equals(flip_str('level'), 'level') test.assert_equals(flip_str('abcdefghijklmnopqrstuvwxyz'), 'zyxwvutsrqponmlkjihgfedcba') test.assert_equals(flip_str('1234567890'), '0987654321')
- import codewars_test as test
from solution import reverse_string- from solution import flip_str
@test.describe("Solution")- @test.describe("Testing")
- def a():
@test.it("should test for something")- @test.it("String Reversal Tests")
- def a():
test.assert_equals(reverse_string('abc'), 'cba')test.assert_equals(reverse_string('123'), '321')test.assert_equals(reverse_string('a1b2c3'), '3c2b1a')test.assert_equals(reverse_string('Hello World!'), '!dlroW olleH')test.assert_equals(reverse_string('Capre diem'), 'meid erpaC')test.assert_equals(reverse_string('Lorem ipsum dolor sit amet!'), '!tema tis rolod muspi meroL')test.assert_equals(reverse_string('abcdefghijklmnopqrstuvwxyz'), 'zyxwvutsrqponmlkjihgfedcba')- test.assert_equals(flip_str(''), '')
- test.assert_equals(flip_str('a'), 'a')
- test.assert_equals(flip_str('hello'), 'olleh')
- test.assert_equals(flip_str('world'), 'dlrow')
- test.assert_equals(flip_str('hello world'), 'dlrow olleh')
- test.assert_equals(flip_str('abc123!@#'), '#@!321cba')
- test.assert_equals(flip_str('HelloWorld'), 'dlroWolleH')
- test.assert_equals(flip_str('level'), 'level')
- test.assert_equals(flip_str('abcdefghijklmnopqrstuvwxyz'), 'zyxwvutsrqponmlkjihgfedcba')
- test.assert_equals(flip_str('1234567890'), '0987654321')