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
4 Respostas
+ 1
score = 100
for i in range(4):
shot=input()
if shot == "hit":
score+=10
elif shot == "miss":
score-=20
print(score)
+ 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
+ 1
Muhammad , are you sure that result value can be different at every iteration?
You gave result input just one time.
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.