'Loop code how to write a while loop for this
What is the best way to code the problem below and how to write it?
for every -A- one point for every Ab - two points
my_pkg = 'AbcdAklpA'
Solution 1:[1]
Here is one way to do so:
points = 0
my_pkg = 'AbcdAklpA'
for i in range(len(my_pkg)):
if my_pkg[i:i+2] == "Ab":
points += 2
if my_pkg[i:i+1] == "A":
points += 1
print(points) # 5
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cubix48 |
