25.2 Python for Beginners “pull the trigger” | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

25.2 Python for Beginners “pull the trigger”

Need some help with my code! 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.

23rd Sep 2021, 7:04 PM
Tyler Richardson
Tyler Richardson - avatar
4 Answers
+ 3
points = 100 tries = 4 while tries > 0: result = (input()) if result == "hit": points +=10 tries -=1 #bug else: result == "miss" #bug points -=20 #bug tries -=1 #bug print (points) #👇debug points = 100 tries = 4 while tries > 0: result = input() if result == "hit": points +=10 elif result == "miss": points -=20 tries -=1 print (points)
23rd Sep 2021, 7:22 PM
Solo
Solo - avatar
+ 2
Thank you!!
24th Sep 2021, 4:34 PM
Tyler Richardson
Tyler Richardson - avatar
0
points = 100 tries = 4 while tries > 0: result = (input()) if result == "hit": points +=10 tries -=1 else: result == "miss" points -=20 tries -=1 print (points)
23rd Sep 2021, 7:04 PM
Tyler Richardson
Tyler Richardson - avatar
0
Thanks you so much for helping, I was a bit confused.
18th Feb 2022, 2:57 AM
Aakash Maderna
Aakash Maderna - avatar