-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path014.py
More file actions
36 lines (31 loc) · 929 Bytes
/
014.py
File metadata and controls
36 lines (31 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# https://www.freecodecamp.org/learn/daily-coding-challenge/2025-08-24
def battle(my_army, opposing_army):
if len(my_army) < len(opposing_army):
return "We retreated"
elif len(my_army) > len(opposing_army):
return "Opponent retreated"
my_wins = 0
for i in range(len(my_army)):
my_value = get_value(my_army[i])
opposing_value = get_value(opposing_army[i])
if my_value > opposing_value:
my_wins += 1
elif my_value < opposing_value:
my_wins -= 1
if my_wins > 0:
return "We won"
elif my_wins < 0:
return "We lost"
else:
return "It was a tie"
def get_value(char):
if char.isalpha():
unicode = ord(char)
if char.isupper():
return unicode - 38
else:
return unicode - 96
elif char.isdigit():
return int(char)
else:
return 0