Advertisement
dariokl

Code Wars

Dec 13th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. '''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.
  2.  
  3. For instance:
  4.  
  5. camelcase("hello case") => HelloCase
  6. camelcase("camel case word") => CamelCaseWord'''
  7.  
  8. def camel_case(string):
  9.     final = [x.title() for x in string.split()]
  10.     make_string = ''.join(map(str, final))
  11.     return make_string
  12.  
  13.  
  14. class Fighter(object):
  15.     def __init__(self, name, health, damage_per_attack):
  16.         self.name = name
  17.         self.health = health
  18.         self.damage_per_attack = damage_per_attack
  19.  
  20.     def __str__(self): return "Fighter({}, {}, {})".format(self.name, self.health, self.damage_per_attack)
  21.     __repr__=__str__
  22.    
  23.    
  24. def declare_winner(fighter1, fighter2, first_attacker):
  25.     turn = 0
  26.     if first_attacker == fighter1.name:
  27.         while fighter1.health >= 0 and fighter2.health >= 0:
  28.             fighter2.health -= fighter1.damage_per_attack
  29.             fighter1.health -= fighter2.damage_per_attack  
  30.             turn = turn + 1
  31.        
  32.             if fighter1.health > fighter2.health:
  33.                 return fighter1.name
  34.             elif fighter1.health < fighter2.health:
  35.                 return fighter2.name
  36.                
  37.     elif first_attacker == fighter2.name:
  38.         while fighter1.health > 0 and fighter2.health > 0:
  39.             fighter1.health -= fighter2.damage_per_attack
  40.             fighter2.health -= fighter1.damage_per_attack  
  41.             turn = turn + 1
  42.            
  43.             result = fighter1.health
  44.            
  45.             print(result)
  46.            
  47.  
  48.  
  49. print(declare_winner(Fighter("Jerry", 30, 3), Fighter("Harald", 20, 5), "Harald"))
  50.  
  51. Complete the function/method so that it returns the url with anything after the anchor (#) removed.
  52. Examples
  53.  
  54. # returns 'www.codewars.com'
  55. remove_url_anchor('www.codewars.com#about')
  56.  
  57. # returns 'www.codewars.com?page=1'
  58. remove_url_anchor('www.codewars.com?page=1')
  59.  
  60. def remove_url_anchor(url):
  61.     letters = [x for x in url]
  62.     if '#' in letters:
  63.         numb = letters.index('#')
  64.         full = ''.join(letters)
  65.         return full[:numb]
  66.     else:
  67.         return url
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement