+ 4
[SOLVED]Code-Coach Challenge : How Far ?
Hey Guys Ryan Here, I Wrote A Code For This Code Coach Challenge But Getting Error In Test Case #3 And #4. Here Is My Solution Can You Please Tell Me Bug Or Error Inside My Code. My Solution : https://code.sololearn.com/cLb163ICe3jM/?ref=app
12 Réponses
+ 5
Try this shorter code,
a=input()
x = a.rstrip("B")
y=x.lstrip("B")
count=0
for i in y:
count+=1
print(count-2)
code by SYED SAIF
+ 3
Ohh that's great👍👍😇😇
+ 2
Thanks 𝕊𝕆𝕌𝕄𝕐𝔸 𝕊𝔸ℍ𝕌 But I Already Solved It Few Minutes Before 😊😊.
+ 2
STEP = 1
s = input()
h = s.find('H')
p = s.find('P')
if p > h:
print(p-h-STEP)
else:
print(h-p-STEP)
+ 1
Ryan Daniel
Most of the users don't have pro account so please also upload the question so more people can help you.
Thanks!
+ 1
Hacker Badshah I Uploaded Question Inside Codebox.
+ 1
Check it out‼
👇👇👇👇
x=input("enter=")
print(x,"\n\n")
a,b=0,0
for i in x:
if i=='H':
a=x.index(i)
elif i=='P':
b=x.index(i)
print(abs(a-b)-1)
+ 1
$hanthi Reddy that's great ... Keep it up 👍
+ 1
a = input()
h = a.index('H')
p = a.index('P')
blocks = (p - h - 1) if p > h else (p + h - 1)
print(blocks)
0
My take:
a = input()
h = a.index('H')
p = a.index('P')
blocks = (p - h - 1) if p > h else (p + h - 1)
print(blocks)
0
Here's my solution, it only passes on 3 out 5 cases, am I missing anything?
walk = input()
started = False
blocks = 0
for i in walk:
if i == "H":
started = True
if started:
if i == "B":
blocks += 1
elif i == "P":
break
print(blocks)
0
William Mabotja consider the situation that P comes before H in which case your code will not work.. just giving a guess to why it didn't work