Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''Write simple .camelCase method (camel_case function in PHP, CamelCase in C# or camelCase in Java) for strings. All words must have their first letter capitalized without spaces.
- For instance:
- camelcase("hello case") => HelloCase
- camelcase("camel case word") => CamelCaseWord'''
- def camel_case(string):
- final = [x.title() for x in string.split()]
- make_string = ''.join(map(str, final))
- return make_string
- class Fighter(object):
- def __init__(self, name, health, damage_per_attack):
- self.name = name
- self.health = health
- self.damage_per_attack = damage_per_attack
- def __str__(self): return "Fighter({}, {}, {})".format(self.name, self.health, self.damage_per_attack)
- __repr__=__str__
- def declare_winner(fighter1, fighter2, first_attacker):
- turn = 0
- if first_attacker == fighter1.name:
- while fighter1.health >= 0 and fighter2.health >= 0:
- fighter2.health -= fighter1.damage_per_attack
- fighter1.health -= fighter2.damage_per_attack
- turn = turn + 1
- if fighter1.health > fighter2.health:
- return fighter1.name
- elif fighter1.health < fighter2.health:
- return fighter2.name
- elif first_attacker == fighter2.name:
- while fighter1.health > 0 and fighter2.health > 0:
- fighter1.health -= fighter2.damage_per_attack
- fighter2.health -= fighter1.damage_per_attack
- turn = turn + 1
- result = fighter1.health
- print(result)
- print(declare_winner(Fighter("Jerry", 30, 3), Fighter("Harald", 20, 5), "Harald"))
- Complete the function/method so that it returns the url with anything after the anchor (#) removed.
- Examples
- # returns 'www.codewars.com'
- remove_url_anchor('www.codewars.com#about')
- # returns 'www.codewars.com?page=1'
- remove_url_anchor('www.codewars.com?page=1')
- def remove_url_anchor(url):
- letters = [x for x in url]
- if '#' in letters:
- numb = letters.index('#')
- full = ''.join(letters)
- return full[:numb]
- else:
- return url
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement