0
It is showing an error in the 5th line i.e. in the variable result. Thank you in advance for your assistance pals
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. points = 100 tries = 4 while tries > 0: result = input() if result == "hit": points += 20 tries -= 1 elif result == "miss": points -= 20 tries -= 1 print("points")
2 ответов
+ 3
Your code suffers from indentation problem. The `if...elif` block should be aligned at the same indentation level with the `while` loop body, the same goes for the line that prints variable <points>.
Also you don't need double quotes for printing variable <points>. It should be:
print( points )
Rather than
print( "points" )
Learn more about code indentation from this 👇
https://code.sololearn.com/cT5BRIbkia21/?ref=app
+ 1
Sanchit Bahl
Your indentation is wrong after 4th line. So, it cause an error.
In this challenge when the input is hit add 10 to the points. But you added 20.
In last line you have only print a string not a variable.
Correct code↓
points = 100
tries = 4
while tries > 0:
result = input()
if result == "hit":
points += 10
tries -= 1
elif result == "miss":
points -= 20
tries -= 1
print(points)