0

I'm trying create a program that takes 4 action results as input( hit or miss) and outputs the score

The player has 4 chances and starts with a score of 100. If he hits the target 10 points are added to his score and if he misses 20 are deducted. This was my program shots = 4 score = 100 while shots > 0: result = input() if result = "hit": shots -= 1 score += 10 print result elif result = " miss " shots -= 1 score -= 20 print result USING A WHILE LOOP

12th Jul 2021, 2:21 PM
Philippe Ezekiel
Philippe Ezekiel - avatar
4 Respuestas
+ 1
score = 100 for i in range(4): shot=input() if shot == "hit": score+=10 elif shot == "miss": score-=20 print(score)
12th Jul 2021, 2:33 PM
Shadoff
Shadoff - avatar
+ 1
shots = 4 score = 100 for i in range(shots): result = input() if result == "hit": shots -= 1 score += 10 elif result == "miss": shots -= 1 score -= 20 else: print("please enter hit or miss") print(score) Mark: u should run my code on other IDE than sololearn to know how the code work
12th Jul 2021, 2:41 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 1
Muhammad , are you sure that result value can be different at every iteration? You gave result input just one time.
12th Jul 2021, 2:44 PM
Shadoff
Shadoff - avatar
0
It looks line python2. Also I'm not sure if your intended didn't get messed up. If you tested on sololearn playground, the input in the while loop probably didn't work.
12th Jul 2021, 2:28 PM
Lisa
Lisa - avatar