PYTHON WHILE LOOP HIT OR MISS GAME MULTIPLE USER INPUT | Sololearn: Learn to code for FREE!

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.

2/24/2021 7:42:49 PM

Courtney Ruth

11 Answers

New Answer

+1

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)

+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

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

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)

0

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

0

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)

0

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

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

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

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)