0
PYTHON WHILE LOOP HIT OR MISS GAME MULTIPLE USER INPUT
PROMPT: 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 EXAMPLE INPUT: HIT MISS HIT HIT EXAMPLE OUTPUT: 110 IT FINDS THE FIRST ONE INFINTELY BC I DONT KNOW HOW TO STORE IT AND MOVE ON TO THE NEXT INPUT TO THEN ADD IT ALL TOGETHER.
19 RĂ©ponses
+ 4
For me this worked:
score = 100
a = 0
while a <= 3:
i = input()
if(i == "hit"):
score = score + 10
if(i == "miss"):
score = score - 20
a = a + 1
print(score)
+ 3
its odd though that i havent gone through learning for loops, the curriculum has only covered while. for loops are next. but the point of this exercise is to use a while loop
+ 3
you can then do something like this,
score=100
count=4
while count! =0:
accuracy=input()
if accuracy=="HIT":
score+=10
elif accuracy=="MISS":
score-=20
count-=1
print(score)
+ 1
I'm also having issues with this code. Here is what I have so far:
#your code goes here
x = 0
points = 100
while x < 5:
score = input()
if score == 'hit':
points += 10
if score == 'miss':
points -= 20
I'm getting an EOF error, from my research this means the input() is not receiving any data
+ 1
Its because your âinput()â is not inside the while loop I guess. Because of that, it takes the first input 4 times and doesnt take 4 diffrent inputs
+ 1
Here is the deal: Sololearn does not explain the issue of incorporating the input() function in an appropriate way. I do not know that I must incorporate the input() function INSIDE of the while loop, because I was putting it at the beginning of it, in the first line, like I would do it in Java. I have no idea that I must indicate the function in the block and not out of the block, like a general position. This is something to consider in the future.
score = 100
action = 1
while action <= 4:
shoot = input()
if(shoot == âhitâ):
score = score + 10
if(shoot == âmissâ):
score = score â 20
action = action + 1
print(score)
+ 1
This will work 100% fine.
score = 100
count = 1
while count <= 4:
i = input()
if(i == "hit"):
score = score + 10
if(i == "miss"):
score = score - 20
count +=1
print(score)
0
WHAT I HAVE RIGHT NOW
ACCURACY = INPUT()
SCORE = 100
WHILE ACCURACY:
IF ACCURACY == âHITâ:
PRINT(SCORE + 10)
ELIF ACCURACY = âMISSâ:
PRINT(SCORE-20)
0
chance = 0
limit = 4
score = 100
while chance < limit:
shot = input(f'{chance}. hit or miss: ')
if shot == 'hit':
score += 10
elif shot == 'miss':
score -= 20
chance += 1
print(score)
0
scores = 100
actions = 4
while actions != 0:
shoot = input()
if shoot == "hit":
scores += 10
actions -= 1
elif shoot == "miss":
scores -= 20
actions -= 1
print(scores)
0
score=100
for i in range(4) :
accuracy=input()
if accuracy=="HIT":
score+=10
elif accuracy=="MISS":
score-=20
print(score)
0
This seems to work for me
score = 100
shot = 3
while shot >= 0:
i = input()
if i == "hit":
score += 10
if i == "miss":
score -= 20
shot -= 1
print(score)
0
score = 100
action = 0
while action <= 3:
i = input()
if(i == "hit"):
score = score + 10
if(i == "miss"):
score = score - 20
action +=1
print(score)
0
a, running = 100, 0
while running < 4:
message = str(input())
if message == 'hit':
a = a + 10
running +=1
elif message == 'miss':
a = a - 20
running +=1
print(a)
0
score=100
count=4
while count != 0:
result = input()
if result == "hit":
score += 10
elif result == "miss":
score -= 20
count -= 1
print(score)
0
chance=0
limit=4
point=100
while chance<limit:
match = input()
if match == 'hit':
point+=10
elif match == 'miss':
point-=20
chance+=1
print(point)
0
options = """the options are
hit
miss
stay"""
print(options)
n = 0
points = 0
while n <= 15:
choice = input("what is your choice? ")
if choice == "hit":
points += 1
print(f"total points:{points} ")
elif choice == "miss":
points -= 1
print(f"total points:{points} ")
elif choice == "stay":
points += 0
print(f"total points:{points} ")
else:
print("type in the right choice")
n += 1
print(f"total points:{points} ")
- 1
It should be like,
score=100
for i in range(4) :
accuracy=input()
if accuracy=="HIT":
score+=10
elif accuracy=="MISS":
score-=20
print(score)
- 1
I wrote this but it seems to continue with what the first input is, for example, if it starts with âhitâ it will repeat that regardless of whether the rest are 'hits' or âmissâ. if the first input is hit then the answer will be 140, but when the first input is miss, the answer is 20
x = 4
points = 100
accuracy = input()
while x > 0:
if accuracy == 'hit':
points += 10
elif accuracy == 'miss':
points -= 20
x -= 1
print(points)