0
Loop is not looping
Performing first action and then stops https://code.sololearn.com/c5YPN01J442s/?ref=app Thanks a million in advance
10 Respostas
+ 5
James
x = 100
n = 0
# only need 0, 1, 2, 3 so < in loop no =
while n < 4:
# input must be inside while loop
action = input()
n += 1
# only really matters if hit -
# miss is the same as else so no condition needed
if action == 'hit': x += 10
else: x -= 20
print(x)
+ 6
James, the EOF error is thrown because you enter less than four commands.
I am trying to help you by wasting time fixing your stupid code, and you, in response, without understanding this, put "dislike" to the correct answer. đ
đđđđđđđđđđđđ
+ 4
Check your indentation.
+ 4
Just want to thank everyone for the help this is a awesome community
Thanks a million
+ 3
while n <= 4:
n += 1
action = input()
if action == 'hit': x += 10
elif action == 'miss': x -= 20
+ 3
I suggest you use this command to make the letter lowercase and it removes space.
action = input().lower().strip()
+ 2
James
Your code is working.
Are you getting an EOF error?
In Sololearn playground, all inputs must be submitted together.
hit
hit
hit
miss
x = 110
+ 1
In the test case
Hit
Miss
Hit
Miss
Yields the same 110 yet answer is 80
miss
hit
miss
hit
yields 80 yet the answer is 70
first action taken and all other are disregarded
+ 1
while n <= 4:
n += 1
action = input()
if action == 'hit': x += 10
elif action == 'miss': x -= 20
print(x)
yields eof error on action = input() line
+ 1
There have to be exactly four iterations with one input each. So you can start with n = 0 and use n < 4 in the while clause or with n = 1 and use n <= 4. And there can be no additional input statement.