It is showing an error in the 5th line i.e. in the variable result. Thank you in advance for your assistance pals | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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")

24th Jun 2021, 2:38 AM
Sanchit Bahl
Sanchit Bahl - avatar
2 Answers
+ 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
24th Jun 2021, 2:52 AM
Ipang
+ 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)
24th Jun 2021, 2:51 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar