Loop is not looping | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Loop is not looping

Performing first action and then stops https://code.sololearn.com/c5YPN01J442s/?ref=app Thanks a million in advance

11th Nov 2021, 10:16 PM
James
10 Answers
+ 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)
11th Nov 2021, 11:57 PM
BroFar
BroFar - avatar
+ 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. 😠 👎👎👎👎👎👎👎👎👎👎👎👎
12th Nov 2021, 8:17 AM
Solo
Solo - avatar
+ 4
Check your indentation.
11th Nov 2021, 10:28 PM
Simon Sauter
Simon Sauter - avatar
+ 4
Just want to thank everyone for the help this is a awesome community Thanks a million
13th Nov 2021, 7:32 PM
James
+ 3
while n <= 4: n += 1 action = input() if action == 'hit': x += 10 elif action == 'miss': x -= 20
11th Nov 2021, 10:46 PM
Solo
Solo - avatar
+ 3
I suggest you use this command to make the letter lowercase and it removes space. action = input().lower().strip()
12th Nov 2021, 9:15 AM
SoloProg
SoloProg - avatar
+ 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
11th Nov 2021, 10:21 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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
11th Nov 2021, 10:28 PM
James
+ 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
11th Nov 2021, 11:10 PM
James
+ 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.
11th Nov 2021, 11:29 PM
Simon Sauter
Simon Sauter - avatar