- 1
8 ответов
+ 2
Question is this:
You are making a game! The player tries to shoot an object and can hit or miss it.
The player starts with 100 points, with a hit adding 10 points to the player’s score, and a miss deducting 20 points.
Your program needs to take 4 action results as input ("hit" or "miss"), calculate and output the player’s remaining points.
Sample Input
hit
hit
miss
hit
Sample Output
110
Explanation: 3 hits add 30 points, one miss deducts 20, making the total points equal to 110.
+ 2
Yuning An
I ran your code ,it doesnt seem to have an eof error,but it does have a logic error.
First you cant just check input like that,store it into a variable and check if that variable is hit or miss
Second,the indentation of your i = i +1 is outside the while loop,its supposed to be inside so after every while loop it gets incremented.
+ 1
s = 100
i = 1
while i <=4:
input('hit' or 'miss')
if 'hit':
s = s + 10
else:
s = s - 20
i = i + 1
print(s)
The input() line has an eof error and I don’t know how to solve it.
+ 1
Maybe your input?
+ 1
The eof error is caused by the logic errors that raynard has pointed out. Your code causes an infinite loop and every iteration of the loop requires input. Therefore the code requires an infinite amount of inputs. The code keeps looking for input that never comes. So in a way the file ends before the programme receives all the input it needs.
0
Are you using file handling i guess post your code here so its easy for community to help you
0
1. You will always have True, so that you do not write, as any character is True.
2. You will output the result of the input, but this is not provided by the task.
3. Don't forget about proper indentation, this is the core of Python.
0
Wait in that input how do you test it with if statement when it is not stored and that condition statement is not well written